How to Kill or Resume [1]+ Stopped Unix Jobs

advertisements

_____________________________________________________________________________________________________________________

The Eucharistic Miracles of the World
When you press ctrl-z on actively running job or command it will suspend the job and release the prompt. But the job will be stopped and remain idle in the back ground. If you try to logout the window or session you will get a message saying “There are stopped jobs.” You can stop or resume the jobs using following commands.
jobs –p command will give the process id for the suspended job.
jobs –l command will list the details of the suspended job
See examples below.
$ sleep 1000
[1]+  Stopped                 sleep 1000
$ exit
logout
There are stopped jobs.
$ jobs -p
28998
$ jobs -l
[1]+ 28998 Stopped                 sleep 1000
$ kill -9 `jobs -p`
[1]+  Killed                  sleep 1000
2. using kill %: this command will kill the last suspended job in the terminal by default and if you specify the number of the suspended job it will kill the mentioned job with %?
Example 1
[1]+  Stopped                 sleep 1000
$ kill %
[1]+  Terminated              sleep 1000
$ sleep 1000
[1]+  Stopped                 sleep 1000
$ kill %1
[1]+  Terminated              sleep 1000
Example 2
$ sleep 1000
[1]+  Stopped                 sleep 1000
$ sleep 10000
[2]+  Stopped                 sleep 10000
$
$ kill %
[2]-  Terminated              sleep 10000
$ kill %
[1]+  Terminated              sleep 1000
How to resume the job?
fg % command will bring the suspended job to the active terminal and bg % command will bring back the job to the background.
$ sleep 10000
[1]+  Stopped                 sleep 10000
fg %1
sleep 10000
[1]+  Stopped                 sleep 10000
bg %1

_____________________________________________________________________________________________________________________

Website Stats

0 comments:

Post a Comment

Labels

Oracle (629) Script (86) General (77) Unix (47) Blog (23) Technology (19) gadget (6) games (6) Business (3) OCI (3) SQL* Loader (3) Datapump (2)
 

acehints.com Copyright 2011-23 All Rights Reserved | Site Map | Contact | Disclaimer