process control

# lists jobs in current session
$ jobs

# start job 1 (sleeps for 200 seconds)
$ sleep 200

# suspended job 1 using control-z
[1] + Stopped sleep 200

# start job 2 (sleeps for 400 seconds)
$ sleep 400

# suspended job 2 using control-z
[2] + Stopped sleep 400

# lists jobs in current session shows the jobs are suspended i.e. not running
$ jobs
[2] + Stopped sleep 400
[1] – Stopped sleep 200

# place sleep 400 in background
$ bg %2
[2] sleep 400

# shows job status sleep 400 is running and 1 is stopped/suspended
$ jobs
[1] + Stopped sleep 200
[2] – Running sleep 400

# place sleep 200 in background
$ bg %1
[1] sleep 200

# shows job status both are running
$ jobs
[1] + Running sleep 200
[2] – Running sleep 400

# place sleep 200 job in foreground
$ fg %1
sleep 200

# pressed control-z to suspend sleep 200
[1] + Stopped sleep 200

# show job status sleep 200 is suspended and sleep 400 is running
$ jobs
[1] + Stopped sleep 200
[2] – Running sleep 400

# wait for suspended job wait will return immediately as it is not running
$ wait %1

# show job status sleep 200 is suspended and sleep 400 is running
$ jobs
[1] + Stopped sleep 200
[2] – Running sleep 400

# place job 1 (sleep 200) in background so it will run
$ bg %1
[1] sleep 200

# wait tells to wait for sleep 200 to finish
$ wait %1

[2] + Done sleep 400

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s