sh Job Control List, wait and stop processes


Example

To get a list of the processes running in the current terminal, you can use ps :

$ sleep 1000 &
$ ps -opid,comm
  PID COMMAND
 1000 sh
 1001 sleep
 1002 ps

To kill a running process, use kill with the process ID (PID) indicated by ps:

$ kill 1001
$ ps -opid,comm
 PID COMMAND
1000 sh
1004 ps

To wait for a process to terminate, use the wait command :

$ sleep 10 && echo End &
$ ps -opid,comm
 PID COMMAND
1000 sh
1005 sh
1006 sleep
1007 ps
$ wait 1005 && echo Stop waiting
End
Stop waiting

First, we run a process with PID 1005 in background which will print "End" before ending. Then, we wait for this process to finish, and print "Stop waiting". The output shows "End", meaning the process with PID 1005 is complete, then "Stop waiting", showing the wait command is complete.