Place and manage tasks or jobs in the background from the comand line

Contributor Icon Contributed by MickeyMouse Date Icon August 22, 2005  
Tag Icon Tagged: UNIX

Managing tasks or jobs from the command line or terminal is easy in unix flavors once you know the simple commands.


Unix, like other modern operating systems, can easily run multiple tasks at once. If you running from the command line or terminal, it is not obvious how to do this or manage these tasks.

In unix running tasks are typically called jobs. While running any job, you can stop it by pressing CTRL-Z. Your prompt will once again appear and you can run more jobs while the original job continues to be active but stopped in the background.

If you want to see what jobs are running, just type jobs. You still see something like this…

[1]+ Stopped NameofJob

    1 is the job number, stopped is the status of the job, and NameofJob is the name of the process that you stopped with CTRL-Z

To restart a job in the background, just type bg %jobnumber. In our case, we would type bg %1.

To restart a job in the foreground, just type fg %jobnumber. In our case, we would type fg %1.

jobs -pl will give you a list of the jobs plus the process id:

[1]+ 26427 Stopped NameofJob

    26427 is the process id in this sample.

Knowing the process id is nice because you can use it to completely stop a job. The format of this command is the following:

kill -15 processid will attempt to shutdown the job safely.
kill -9 processid is used more frequently and just aborts the job.

Therefore, to stop NameofJob with process id of 26427 I would type:

    kill -9 26427
Previous recipe | Next recipe |
 

 
close Reblog this comment
blog comments powered by Disqus