Jobs and Concurrency ==================== commands * ``jobs`` * ``ps`` * ``fg`` bring background process to the foreground * ``bg`` resume a stopped background process if it is stopped * ``disown`` * ``kill`` Running Tasks in the background ------------------------------- Tasks can be run concurrently in the background with the ``&`` operator. .. code-block:: bash # run 3 commands in a background jobs tail -f /var/log/dmesg & tail -f /var/log/syslog & nano /tmp/file & # Three jobs in the background # list background jobs and their statuses and their PIDs jobs -l # list the PIDs only jobs -p # list jobs in the current process and its children ps UNIX Signals ------------ Resources * man 7 signal * kill -L .. csv-table:: :file: signals.csv Stopping and Resuming --------------------- The main signals we are concerned about are: * ``kill -19`` stop process * ``kill -18`` continue if stopped * ``kill -15`` soft termination * ``kill -9`` hard termination jobs can be selected by their order in which they were started with ``%1`` being the first job, ``%2`` being the second job and onwards. .. code-block:: bash tail -f /var/log/dmesg & tail -f /var/log/syslog & nano /tmp/file & # stop the second job kill -19 %2 # stop the first job kill -19 %1 # resume the first job kill -18 %1 # when we terminate the second job, jobs 3 onward maintain their order in the job list kill -15 %2 Current and Child PID --------------------- .. code-block:: bash # prints the current PID VS a child subshell PID echo $BASHPID; ( echo $BASHPID )