How to show the list of stopped and background jobs
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to show the list of stopped and background jobs
what command can give me the list of stopped jobs and the programs that are running background e.g running a program by the command play sound.wav & and jobs stoped by ctrl-Z. i know the fg command now i want to know the list of stopped jobs as i can merely do fg of my own choice.
use "jobs" it lists all backgrounded processes.
then "fg [number]"
eg:
Code:
$jobs
[1] Stopped vim
[2]- Running play sound.wav &
[3]+ Stopped man ps # the plus sign means this process will be foregrounded if you just type fg without a number
$fg 1 #this would bring vim back to the foreground
One reason for me to start jobs in the background is that i want to disconnect from the server, while the jobs gets done.
But when i come back after having been disconnected, there is no mention of the background job when i type "jobs". (But using "top" i can see that my job is still running)
I can reproduce this on my local ubuntu machine:
## ----
$ vim test.txt &
[1] 9516
$ jobs
[1]+ Stopped vim test.txt
# Now i open another teminal.
$ jobs
$
## ----
I can only see the jobs in the first teminal window (bash).
Is there a way to see (my own) jobs from a different session?
can't find it using google and there doesn't seem to be a manpage for "jobs".
It depends exactly what you are trying to do.
When you do
someprog &
it puts it into the background, BUT its still attached to the terminal/login session. If you try to completely logout it should warn you there are running jobs. If you continue to logout, that job should die, although it may possibly hang.
To disconnect the job when starting it, use nohup and '&'
nohup someprog &
from then old days meaning 'no-hangup'.
If its an interactive job you want to be able to re-connect to when you log back in, lookup the 'screen' utility.
One reason for me to start jobs in the background is that i want to disconnect from the server, while the jobs gets done.
But when i come back after having been disconnected, there is no mention of the background job when i type "jobs". (But using "top" i can see that my job is still running)
I can reproduce this on my local ubuntu machine:
## ----
$ vim test.txt &
[1] 9516
$ jobs
[1]+ Stopped vim test.txt
# Now i open another teminal.
$ jobs
$
## ----
I can only see the jobs in the first teminal window (bash).
Is there a way to see (my own) jobs from a different session?
can't find it using google and there doesn't seem to be a manpage for "jobs".
Thanx!
I would like to know this, too. Has it been resolve here? Thanks
yes there is, chrism01 gave the right answer.
I resolved this by installing "screen"
And then when i want to do something that takes too long to stay logged in, i use screen like this:
screen -DR
#the terminal turns blank, this is a new screen session.
Then I type the commands that i want executed which will take such a long time (only disadvantage is you can't scroll back up like normal - what is out of your screen is gone, you cannot scoll back up to it)
Then i just close the terminal window. It warns me "There is still a process running in this terminal. Closing the terminal will kill it.", but it won't, because i am using screen.
Then, when I log back in the next hour,day or week (before the next server reboot), i don't see the screen that i was working in. I first need to go back to my screen session with
screen -DR
my terminal now shows the commands that i typed in the screen session, and possibly the output if it is done.
HTH
Last edited by rudeboy75; 01-09-2012 at 10:23 AM.
Reason: typos & correct quotes
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.