Unix System Programming Overview Outline What Is a Signal? Signal

Total Page:16

File Type:pdf, Size:1020Kb

Unix System Programming Overview Outline What Is a Signal? Signal Overview Last Week: ● How to program UNIX processes (Chapters 7-9) ● fork() and exec() Unix System Programming This Week, and next week: ● UNIX inter-process communication mechanisms: signals, Signals » (next week) pipes and FIFOs. ● How to program with UNIX signals (Chapter 10) » http://en.wikipedia.org/wiki/Unix_signal ● Non-local jumps (Chapter 7) ● Focus on the sigaction() function Maria Hybinette, UGA 1 Maria Hybinette, UGA 2 Outline What is a Signal? ● A signal is an asynchronous event which is ● What is a UNIX signal? delivered to a process (instantiated by a small message) ● Signal types ● Asynchronous means that the event can occur ● Generating signals at any time (e.g., posting at a bulletin board ) ● Responding to a signal » may be unrelated to the execution of the process ● Common uses of a signal – e.g., user types Ctrl-C, or the modem hangs (SIGINT) ● Implementing a read() time-out – e.g,, user types Ctrl-Z (SIGTSTP) ● Sent from kernel (e.g. detects divide by zero ● Non-local jumps setjmp()/longjmp() (SIGFPE) or could be at the request of another ● POSIX signals process to send to another) ● Interrupted system calls ● Only information that a signal carries is its ● System calls inside handlers unique ID and that it arrived Maria Hybinette, UGA 3 Maria Hybinette, UGA 4 Signal Types (31 in POSIX) Signal Sources terminal memory ID Name Description Default Action driver management shell command 2 SIGINT Interrupt from keyboard (^C) terminate Ctr-C SIGINT SIGHUP 3 SIGQUIT Quit from keyboard (^\) terminate & core SIGSEGV 9 SIGKILL kill -9 terminate SIGKILL,SIGCONT kernelsig 11 SIGSEGV Invalid memory reference terminate & core SIGPIPE 14 SIGALRM alarm() clock rings terminate SIGWINCH SIGALRM 17 SIGCHLD Child stopped or terminated! ignore Terminal, window 16 SIGUSR1 user-defined signal type terminate manager a process SIGUSR1 ● /usr/include/sys/iso/signal_iso.h on atlas (solaris) ● /usr/src/kernels/2.6.32-431.29.*/include/linux/signal.h SIGFPE other user ● processes /usrMaria Hybinette,/include/ UGA signal.h (user space)! 5 RunningMaria Hybinette, a.out UGA process (division by 0, floating point exception) 6 Generating a Signal kill() ● Use the UNIX command: {saffron} ./fork_example {saffron} kill -KILL 6676 Terminating Parent, PID = 6675 #include <signal.h> » sends a SIGKILL signal to Running Child, PID = 6676 int kill( pid_t pid, int signo ); {saffron} ps processor ID (pid) 6676 PID TTY TIME CMD 6585 ttyp9 00:00:00 tcsh ● Send a signal to a process (or group of processes). » check pid via (and also to 6676 ttyp9 00:00:06 fork_example ● make sure it died) {saffron} kill –s 9 6676 Return 0 if ok, -1 on error. {saffron} ps {saffron} ps -l PID TTY TIME CMD 6585 ttyp9 00:00:00 tcsh ● Meaning pid 6678 ttyp9 00:00:00 ps > 0 send signal to process pid ● kill is not a good name; == 0 send signal to all processes send_signal might be whose process group ID better. equals the senders pgid. e.g. parent kills all children ● How do we do this in a program? Maria Hybinette, UGA 7 Maria Hybinette, UGA 8 Responding to a Signal signal() #include <signal.h> ● After receiving a signal a process can: 1. Ignore/Discard/Block out the signal (not possible with void (*signal( int signo, void (*func)(int) ))(int); SIGKILL or SIGSTOP) 2. Catch the signal; execute a signal handler function, and typedef void Sigfunc( int ); /* Plauger 1992 definition */ then possibly resume execution or terminate Sigfunc *signal( int signo, Sigfunc *handler ); 3. Carry out the default action for that signal ● Signal returns a pointer to a function that returns an int (i.e. it ● The choice is called the processsignal returns a pointer to Sigfunc) disposition ● Specify a signal handler function to deal with a signal type. ● How is a process disposition set? ● Returns previous signal disposition if OK, SIG_ERR on error. Maria Hybinette, UGA 9 Maria Hybinette, UGA 10 5. signal returns a pointer 4. The handler Sketch on how to program with to a function. 2. The signal to be function The return type is the sameActual caught Prototype or ignored Receives a single signals as the function that is passed is given as argument integer in, signo argument and i.e., a function that takes an returns void ● The actual prototype, listed in the man page is a bit int main() int and returns a void { perplexing but is an expansion of the Sigfunc type: signal( SIGINT, foo ); : void (*signal( int signo, void (*handler)(int)))(int); /* do usual things until SIGINT */ return 0; ● signal returns a pointer to the previous signal handler } 3. The function to be void foo( int signo ) { #include <signal.h> called when the 6. The returned : /* deal with SIGINT signal */ typedef1. signal void takes Sigfunc(int); two specified /* Plauger signal is1992 */ function Sigfuncarguments: *signal( int signo,received Sigfunc is given *handler as ); takes a integer signo and handler parameter. return; /* return to program */ a pointer to the } function handler Maria Hybinette, UGA 11 Maria Hybinette, UGA 12 External Signal Example: signal_example.c #include <stdio.h> int main( void ) {saffron:ingrid:54} signal_example 0: Received SIGUSR1 #include <signal.h> { 1: Received SIGUSR1 #include <unistd.h> int i = 0; 2: Received SIGUSR2 [1] + Stopped (signal) if( signal( SIGUSR1, sig_usr ) == SIG_ERR ) signal_example static void sig_usr( int signo ) perror( "Cannot catch SIGUSR1\n" ); {saffron:ingrid:26} fg { if( signal( SIGUSR2, sig_usr ) == SIG_ERR ) signal_example 3: Received SIGUSR1 if( signo == SIGUSR1 ) perror( "Cannot catch SIGUSR2\n" ); Quit printf( "Received SIGUSR1\n" ); else if( signo == SIGUSR2 ) while( 1 ) printf( "Received SIGUSR2\n" ); { else printf( "%d: ", i ); {saffron:ingrid:55} kill -l= {saffron:ingrid:56} ps -l { pause(); /* until signal handler fprintf( stderr, "ERROR: received signal %d\n", signo ); has processed signal */ {saffron:ingrid:23} kill -USR1 1255 exit(1); i++; {saffron:ingrid:24} kill -USR1 1255 } } {saffron:ingrid:25} kill -USR2 1255 return; return 0; {saffron:ingrid:26} kill -STOP 1255 {saffron:ingrid:27} kill -CONT 1255 } ps –u } {saffron:ingrid:28} kill -USR1 1255 {saffron:ingrid:29} kill QUIT 1255 kill -SIGUSR2 21084 Maria Hybinette, UGA 13 Maria Hybinette, UGA 14 Internal Signal Example: signal_example2.c Special Sigfunc * Values #include <stdio.h> int main( void ) #include <signal.h> { #include <unistd.h> int i = 0; ● Value Meaning if( signal( SIGALRM, handler ) == SIG_ERR ) int beeps = 0; perror( "Cannot catch SIGALRM\n" ); alarm(1); SIG_IGN Ignore / discard the signal. static void handler( int signo ) while( 1 ) { { printf( "BEEP\n" ); printf( "%d: ", i ); SIG_DFL Use default action to handle signal. fflush(stdout); pause(); i++; } SIG_ERR Returned by signal() as an error. if( ++beeps < 5 ) return 0; alarm(1); } else { {cinnamon} signal_example2 printf("BOOM!\n"); 0: BEEP exit(0); 1: BEEP } 2: BEEP return; 3: BEEP } 4: BEEP BOOM! Maria Hybinette, UGA 15 Maria Hybinette, UGA 16 Multiple Signals pause() ● If many signals of the same type are waiting to #include <unistd.h> be handled (e.g. two SIGINTs), then most UNIXs int pause(void); will only deliver one of them. » the others are thrown away - i.e. pending signals are not queued ● Suspend the calling process until a signal is caught. » for each signal type, just have a single bit indicating whether or not the signal has occured ● Returns -1 with errno assigned EINTR. ● If many signals of different types are waiting to (Linux assigns it ERESTARTNOHAND). be handled (e.g. a SIGINT, SIGSEGV, SIGUSR1), ● pause() only returns after a signal handler they are not delivered in any fixed order. has returned. Maria Hybinette, UGA 17 Maria Hybinette, UGA 18 The Reset Problem Reset Problem Example ● In Linux (and many other UNIXs), the signal int main() disposition in a process is reset to its default { signal(SIGINT, foo); action immediately after the signal has been : delivered. /* do usual things until SIGINT */ } void foo( int signo ) { ● Must call signal() again to reinstall the signal(SIGINT, foo); /* reinstall */ signal handler function. : return; } Maria Hybinette, UGA 19 Maria Hybinette, UGA 20 To keep catching the signal with this function, must call Reset Problem the signal system Re-installation may be too slow! call again. : void ouch( int sig ) ● There is a (very) small time period in foo() when { a new SIGINT signal will cause the default action printf( "OUCH! - I got signal %d\n", sig ); to be carried out -- process termination. (void) signal( SIGINT, ouch ); } Problem: from the time int main() that the interrupt function ● With there is no answer to this starts to just before the signal() { signal handler is re- problem. (void) signal( SIGINT, ouch ); established » POSIX signal functions solve it (and some other later while(1) the signal will not be UNIXs) { handled. printf( "Hello World!\n"); sleep(1); } If another SIGINT signal is } received during this time, default behavior will be done, i.e., program will terminate. Maria Hybinette, UGA 21 Maria Hybinette, UGA 22 Common Uses of Signals Ignore a Signal : ● Ignore a signal int main() { ● Clean up and terminate signal( SIGINT, SIG_IGN ); signal( SIGQUIT, SIG_IGN ); ● Dynamic reconfiguration : /* do work without interruptions */ ● Report status } ● Turn debugging on/off ● Cannot ignore/handle SIGKILL or SIGSTOP ● Restore a previous handler ● Should check for SIG_ERR Maria Hybinette, UGA 23 Maria Hybinette, UGA 24 Clean up and Terminate Checking the Disposition ● If a program is run in the new disposition : old disposition /* global variables */ background then
Recommended publications
  • Systems Programming II
    Systems Programming II Iqbal Mohomed CSC 209 – Summer 2004 Week 7 Motivation for Signals • When a program forks into 2 or more processes, rarely do they execute independently of each other • The processes usually require some form of synchronization, and this is typically handled using signals. Job control is another important use • Data usually needs to be passed between processes also, and this is typically handled using pipes and sockets, which we will discuss shortly • Signals are usually generated by – Machine interrupts – The program itself, other programs, or the user (i.e. from the keyboard) Introduction to Signals • When a C program receives a signal, control is immediately passed to a function called a signal handler • The signal handler function can execute some C statements and exit in three different ways: – Return control to the place in the program which was executing when the signal occurred – Return control to some other point in the program – Terminate the program by calling the exit (or _exit) function signal() • A default action is provided for each kind of signal, such as terminate, stop or ignore • For nearly all signal types, the default action can be changed using the signal() function. The exceptions are SIGKILL and SIGSTOP. The handler is defined as follows: – typedef void (*sighandler_t)(int); • To change the handler: – sighandler_t signal(int signum, sighandler_t handler); More on signal() • For each process, the OS maintains a table of actions that should be performed for each kind of signal. The signal() function changes the table entry for the signal named as the first argument to the value provided as the second argument.
    [Show full text]
  • POSIX Signals
    CSE 410: Systems Programming POSIX Signals Ethan Blanton Department of Computer Science and Engineering University at Buffalo Introduction Signals Blocking Concurrency Sending Signals Summary References POSIX Signals POSIX signals are another form of interprocess communication. They are also a way to create concurrency in programs. For these two reasons, they are rather complicated and subtle! Signals provide a simple message passing mechanism. © 2018 Ethan Blanton / CSE 410: Systems Programming Introduction Signals Blocking Concurrency Sending Signals Summary References Signals as Messages POSIX signals are asynchronous messages. Asynchronous means that their reception can occur at any time.1 The message is the reception of the signal itself. Each signal has a number, which is a small integer. POSIX signals carry no other data. 1Almost. We’ll see how to control it later. © 2018 Ethan Blanton / CSE 410: Systems Programming Introduction Signals Blocking Concurrency Sending Signals Summary References Signal Types There are two basic types of POSIX signals: Reliable signals Real-time signals Real-time signals are much more complicated. In particular, they can carry data. We will discuss only reliable signals in this lecture. © 2018 Ethan Blanton / CSE 410: Systems Programming Introduction Signals Blocking Concurrency Sending Signals Summary References Asynchronous Reception From the point of view of the application: Signals can be blocked or ignored Enabled signals may be received between any two processor instructions A received signal can run a user-defined function called a signal handler This means that enabled signals and program code must very carefully manipulate shared or global data! © 2018 Ethan Blanton / CSE 410: Systems Programming Introduction Signals Blocking Concurrency Sending Signals Summary References Signals POSIX defines a number of signals by name and number.
    [Show full text]
  • Programming with POSIX Threads II
    Programming with POSIX Threads II CS 167 IV–1 Copyright © 2008 Thomas W. Doeppner. All rights reserved. Global Variables int IOfunc( ) { extern int errno; ... if (write(fd, buffer, size) == –1) { if (errno == EIO) fprintf(stderr, "IO problems ...\n"); ... return(0); } ... } CS 167 IV–2 Copyright © 2008 Thomas W. Doeppner. All rights reserved. Unix was not designed with multithreaded programming in mind. A good example of the implications of this is the manner in which error codes for failed system calls are made available to a program: if a system call fails, it returns –1 and the error code is stored in the global variable errno. Though this is not all that bad for single-threaded programs, it is plain wrong for multithreaded programs. Coping • Fix Unix’s C/system-call interface • Make errno refer to a different location in each thread – e.g. #define errno __errno(thread_ID) CS 167 IV–3 Copyright © 2008 Thomas W. Doeppner. All rights reserved. The ideal way to solve the “errno problem” would be to redesign the C/system-call interface: system calls should return only an error code. Anything else to be returned should be returned via result parameters. (This is how things are done in Windows NT.) Unfortunately, this is not possible (it would break pretty much every Unix program in existence). So we are stuck with errno. What can we do to make errno coexist with multithreaded programming? What would help would be to arrange, somehow, that each thread has its own private copy of errno. I.e., whenever a thread refers to errno, it refers to a different location from any other thread when it refers to errno.
    [Show full text]
  • POSIX Signal Handling in Java
    Technical Document Series POSIX Signal Handling in Java POSIX Signal Handling In Java Introduction POSIX signals inform a running process of external events, such as the user wishing to kill the process, or the operating system signaling an impending shutdown, or the process being suspended or reinstated; or the process may have violated a resource constraint, such as excessive CPU usage or attempts to access areas outside its permitted memory space, and is asked to shutdown. In short, POSIX signals serve many different purposes. Some are even up to interpretation, such as the HUP (HangUP) signal, which is commonly used to inform a process that something about its environment has changed and the process should adjust accordingly. Some programs may interpret this to mean that the configuration has changed and needs to be reloaded; or the log file has been moved for archiving purposes and a new one should be started. The use of signals is widespread, especially on Unix-based operating systems, but Java provides no standard interface for a Java application to hear and react to them. This document shows you how to get around this limitation. The Good, the Bad, and the Ugly The good news is that there is a way to intercept POSIX signals and react to them in Java. This would allow your Java program to avoid being killable with ^C (SIGINT), for example, even ignore termination requests from the operating system (SIGTERM). Neither of these is necessarily a good idea, of course, unless you know exactly why you would want to catch these signals and either handle them yourself or ignore them altogether.
    [Show full text]
  • Processes and Job Control
    Processes and Job Control Hour 17 PObjectives < Definitions: process, orphan, and zombie < System processes < Process creation < Examining processes: the ps command < Job control: &, nohup, fg, bg, jobs, ( ), and kill < Exit status Copyright © 1998-2002 Delroy A. Brinkerhoff. All Rights Reserved. Hour 17 Unix Slide 1 of 12 Process Also called a job by C and Korn shells PWhen a program or executable file is loaded from disk and started running (i.e., when a command is run), it is called a process vi pid 641 < identified by a unique process ID (PID) number < has an owner vi < private data vi PA program can be loaded more than once pid 895 < creates multiple processes vi < each process has a different PID < each process may have a different owner PPIDs are unique, nonnegative integers < numbers recycle without collisions Hour 17 Unix Slide 2 of 12 System Processes Processes created during system boot P0System kernel < “hand crafted” at boot < called swap in older versions (swaps the CPU between processes) < called sched in newer versions (schedules processes) < creates process 1 P1 init (the parent of all processes except process 0) < general process spawner < begins building locale-related environment < sets or changes the system run-level P2 page daemon (pageout on most systems) P3 file system flusher (fsflush) Hour 17 Unix Slide 3 of 12 Process Life Cycle Overview of creating new processes fork init init pid 467 Pfork creates two identical pid 1 exec processes (parent and child) getty pid 467 Pexec < replaces the process’s instructions
    [Show full text]
  • Site Map - Apache HTTP Server 2.0
    Site Map - Apache HTTP Server 2.0 Apache HTTP Server Version 2.0 Site Map ● Apache HTTP Server Version 2.0 Documentation ❍ Release Notes ■ Upgrading to 2.0 from 1.3 ■ New features with Apache 2.0 ❍ Using the Apache HTTP Server ■ Compiling and Installing Apache ■ Starting Apache ■ Stopping and Restarting the Server ■ Configuration Files ■ How Directory, Location and Files sections work ■ Server-Wide Configuration ■ Log Files ■ Mapping URLs to Filesystem Locations ■ Security Tips ■ Dynamic Shared Object (DSO) support ■ Content Negotiation ■ Custom error responses ■ Setting which addresses and ports Apache uses ■ Multi-Processing Modules (MPMs) ■ Environment Variables in Apache ■ Apache's Handler Use ■ Filters ■ suEXEC Support ■ Performance Hintes ■ URL Rewriting Guide ❍ Apache Virtual Host documentation ■ Name-based Virtual Hosts ■ IP-based Virtual Host Support ■ Dynamically configured mass virtual hosting ■ VirtualHost Examples ■ An In-Depth Discussion of Virtual Host Matching ■ File descriptor limitations ■ Issues Regarding DNS and Apache ❍ Apache Server Frequently Asked Questions http://httpd.apache.org/docs-2.0/sitemap.html (1 of 4) [5/03/2002 9:53:06 PM] Site Map - Apache HTTP Server 2.0 ■ Support ❍ Apache SSL/TLS Encryption ■ SSL/TLS Encryption: An Introduction ■ SSL/TLS Encryption: Compatibility ■ SSL/TLS Encryption: How-To ■ SSL/TLS Encryption: FAQ ■ SSL/TLS Encryption: Glossary ❍ Guides, Tutorials, and HowTos ■ Authentication ■ Apache Tutorial: Dynamic Content with CGI ■ Apache Tutorial: Introduction to Server Side Includes ■ Apache
    [Show full text]
  • System Calls & Signals
    CS345 OPERATING SYSTEMS System calls & Signals Panagiotis Papadopoulos [email protected] 1 SYSTEM CALL When a program invokes a system call, it is interrupted and the system switches to Kernel space. The Kernel then saves the process execution context (so that it can resume the program later) and determines what is being requested. The Kernel carefully checks that the request is valid and that the process invoking the system call has enough privilege. For instance some system calls can only be called by a user with superuser privilege (often referred to as root). If everything is good, the Kernel processes the request in Kernel Mode and can access the device drivers in charge of controlling the hardware (e.g. reading a character inputted from the keyboard). The Kernel can read and modify the data of the calling process as it has access to memory in User Space (e.g. it can copy the keyboard character into a buffer that the calling process has access to) When the Kernel is done processing the request, it restores the process execution context that was saved when the system call was invoked, and control returns to the calling program which continues executing. 2 SYSTEM CALLS FORK() 3 THE FORK() SYSTEM CALL (1/2) • A process calling fork()spawns a child process. • The child is almost an identical clone of the parent: • Program Text (segment .text) • Stack (ss) • PCB (eg. registers) • Data (segment .data) #include <sys/types.h> #include <unistd.h> pid_t fork(void); 4 THE FORK() SYSTEM CALL (2/2) • The fork()is one of the those system calls, which is called once, but returns twice! Consider a piece of program • After fork()both the parent and the child are ..
    [Show full text]
  • NSWI 0138: Advanced Unix Programming
    NSWI 0138: Advanced Unix programming (c) 2011-2016 Vladim´ırKotal (c) 2009-2010 Jan Pechanec, Vladim´ırKotal SISAL MFF UK, Malostransk´en´am.25, 118 00 Praha 1 Charles University Czech Republic Vladim´ırKotal [email protected] March 10, 2016 1 Vladim´ırKotal NSWI 0138 (Advanced Unix programming) Contents 1 Overview 5 1.1 What is this lecture about? . .5 1.2 The lecture will cover... .5 1.3 A few notes on source code files . .6 2 Testing 6 2.1 Why?...........................................6 2.2 When ? . .6 2.3 Types of testing . .7 3 Debugging 8 3.1 Debuging in general . .8 3.2 Observing . .9 3.3 Helper tools . .9 3.3.1 ctags . .9 3.3.2 cscope . 10 3.3.3 OpenGrok . 11 3.3.4 Other tools . 11 3.4 Debugging data . 11 3.4.1 stabs . 11 3.4.2 DWARF . 12 3.4.3 CTF (Compact C Type Format) . 12 3.5 Resource leaks . 13 3.6 libumem . 13 3.6.1 How does libumem work . 14 3.6.2 Using libumem+mdb to find memory leaks . 14 3.6.3 How does ::findleaks work . 16 3.7 watchmalloc . 17 3.8 Call tracing . 18 3.9 Using /proc . 19 3.10 Debugging dynamic libraries . 20 3.11 Debuggers . 20 3.12 Symbol search and interposition . 20 3.13 dtrace . 21 4 Terminals 21 4.1 Terminal I/O Overview . 21 4.2 Terminal I/O Overview (cont.) . 22 4.3 Physical (Hardware) Terminal . 24 4.4 stty(1) command . 24 4.5 TTY Driver Connected To a Phy Terminal .
    [Show full text]
  • Linux Scripting Signals & Traps Signals
    Linux Scripting Signals & Traps Signals • Linux supports both POSIX reliable signals and POSIX real-time signals. • A signal is a “software interrupt” • A signal interrupts a process • The process may halt • The process may “catch” the signal • Signals have no “bodies” Signals • In Linux, every signal has a name that begins with characters SIG. For example : • A SIGINT signal that is generated when a user presses ctrl+c. This is the way to terminate programs from terminal. • A SIGALRM is generated when the timer set by alarm function goes off. • A SIGABRT signal is generated when a process calls the abort function. • Etc To see the signals available on your system type: kill -l Signal Name Description SIGSTOP 19 Stop executing(can't be caught or ignored) (POSIX) SIGHUP 1 Hangup (POSIX) SIGTSTP 20 Terminal stop signal (POSIX) SIGINT 2 Terminal interrupt (ANSI) 21 Background process trYing to read, from TTY SIGQUIT 3 Terminal quit (POSIX) SIGTTIN (POSIX) SIGILL 4 Illegal instruction (ANSI) SIGTTOU 22 Background process trYing to write, to TTY (POSIX) SIGTRAP 5 Trace trap (POSIX) SIGIOT 6 IOT Trap (4.2 BSD) SIGURG 23 Urgent condition on socket (4.2 BSD) SIGBUS 7 BUS error (4.2 BSD) SIGXCPU 24 CPU limit exceeded (4.2 BSD) Floating point exception SIGFPE 8 25 (ANSI) SIGXFSZ File size limit exceeded (4.2 BSD) Kill(can't be caught or SIGVTALRM 26 Virtual alarm clock (4.2 BSD) SIGKILL 9 ignored) (POSIX) SIGPROF 27 Profiling alarm clock (4.2 BSD) User defined signal 1 SIGUSR1 10 (POSIX) SIGWINCH 28 Window size change (4.3 BSD, Sun) Invalid memory
    [Show full text]
  • Processes in Linux/Unix
    Processes in Linux/Unix A program/command when executed, a special instance is provided by the system to the process. This instance consists of all the services/resources that may be utilized by the process under execution. • Whenever a command is issued in unix/linux, it creates/starts a new process. For example, pwd when issued which is used to list the current directory location the user is in, a process starts. • Through a 5 digit ID number unix/linux keeps account of the processes, this number is call process id or pid. Each process in the system has a unique pid. • Used up pid’s can be used in again for a newer process since all the possible combinations are used. • At any point of time, no two processes with the same pid exist in the system because it is the pid that Unix uses to track each process. Initializing a process A process can be run in two ways: 1. Foreground Process : Every process when started runs in foreground by default, receives input from the keyboard and sends output to the screen. When issuing pwd command $ ls pwd Output: $ /home/geeksforgeeks/root When a command/process is running in the foreground and is taking a lot of time, no other processes can be run or started because the prompt would not be available until the program finishes processing and comes out. 2. Backround Process : It runs in the background without keyboard input and waits till keyboard input is required. Thus, other processes can be done in parallel with the process running in background since they do not have to wait for the previous process to be completed.
    [Show full text]
  • Intro to Unix 2018
    Introduction to *nix Bill Renaud, OLCF ORNL is managed by UT-Battelle for the US Department of Energy Background • UNIX operating system was developed in 1969 by Ken Thompson and Dennis Ritchie • Many “UNIX-like” OSes developed over the years • UNIX® is now a trademark of The Open Group, which maintains the Single UNIX Specification • Linux developed by Linus Torvalds in 1991 • GNU Project started by Richard Stallman in 1983 w/aim to provide free, UNIX-compatible OS • Many of the world’s most powerful computers use Linux kernel + software from the GNU Project References: 1www.opengroup.org/unix 2https://en.wikipedia.org/wiki/Linux 2 3https://www.gnu.org/gnu/about-gnu.html This Presentation • This presentation will focus on using *nix operating systems as a non-privileged user in an HPC environment – Assumes you’re using a ‘remote’ system – No info on printing, mounting disks, etc. • We’ll focus on systems using the Linux kernel + system software from the GNU project since that’s so prevalent • Two-Part – Basics: general information, commands – Advanced: advanced commands, putting it all together, scripts, etc. 3 This Presentation • May seem a bit disjoint at first – Several basic concepts that don’t flow naturally but later topics build upon – Hopefully everything will come together, but if not… • I’ll cover (what I hope is) some useful info but can’t cover it all – People write thousand-page books on this, after all • Please ask questions! 4 Basics Terminology • User – An entity that interacts with the computer. Typically a person but could also be for an automated task.
    [Show full text]
  • CST8207 – Linux O/Si
    Processes 1 elinks, mail processes nice ps, pstree, top job control, jobs, fg, bg signals, kill, killall crontab, anacron, at 2 elinks is a text-based (character mode) web browser we will use it to enable our scripts to retrieve web pages in assignment 6, we use it to retrieve a weather webpage elinks -dump -no-numbering -no-references <URL> Example elinks -dump -no-numbering -no-references \ 'http://weather.gc.ca/rss/city/on-118_e.xml' Could grep this to extract information (maybe with –A option) 3 use the mail command to send outgoing and read incoming email on the CLS Sending outgoing email (bold font shows what the user types) $ mail [email protected] Cc: Subject: First Message from CLS This is a test message. ^D $ 4 text mode mail reader incoming email is stored in /var/spool/mail/<username> use the mail command to read it you'll see a list of messages, each preceded by a number (the header list) enter a number to see that message enter h to see the header list again when you enter q, mail will quit and messages you read will be stored in ~/mbox mail –f to see the messages in ~/mbox 5 Any program we run executes as a process Processes have the following attributes ◦ a process id: PID ◦ a parent process id: PPID ◦ a nice number (related to priority) ◦ controlling terminal ◦ Real (RUID) and effective (EUID) user id ◦ Real (RGID) and effective (EGID) group id Also: ◦ a current working directory ◦ a umask value ◦ an environment (values of environment variables) 6 We have already been using the ps command
    [Show full text]