9 Job control Flashcards
Start command or entire pipe as a background job, without connecting stdin to terminal:
$ command &
returns
[shell job id] PID
Job number output by shell
Shell prints both a job number (identifying all processes in pipe) as well as process ID of last process in pipe. Shell will list all its jobs with the jobs command, where a + sign marks the last stopped (default) job.
Foreground job
Stdin connected to terminal, shell prompt delayed until process exits, keyboard signals delivered to this single job.
Background job
Stdin disconnected (read attempt will suspend job), next shell prompt appears immediately, keyboard signals not delivered, shell prints notification when job terminates.
Keyboard signals
change with stty
32 bit int in PCB - other processes can set them, check+possibly invoke signal handler on each system call performed by the process
Ctrl-C “intr” (SIGINT=2) by default aborts process
Ctrl-\ “quit” (SIGQUIT=3) aborts process with core dump Ctrl-Z “susp” (SIGSTOP=19) suspends process
Another important signal (not available via keyboard): SIGKILL=9 destroys process immediately
resume suspended job in foreground
fg
resume suspended job in background
bg
send SIGINT to job/process
kill
Arguments to fg/bg/kill
no args - acts on [1]+ last process to change state
OR provide:
process ID
% + job number
% + command name
send sigkill
kill -9 …
Should only be used as a last resort, if a normal kill (which sends SIGINT) failed, otherwise program has no chance to clean up resources before it terminates.
see list of jobs of current shell
jobs command
list the entire process table
ps
ps -x (many options – check man)
top
fg %, %
run previously stopped job in foreground – allows you to switch between several programs