LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   running in background hangs on shell logout (https://www.linuxquestions.org/questions/linux-newbie-8/running-in-background-hangs-on-shell-logout-305861/)

pfaendtner 03-25-2005 07:24 AM

running in background hangs on shell logout
 
Hi,

When I have a terminal window open (or I'm connected to another computer via ssh) and I submit programs to run in the background with &, the shell always hangs when I type "exit". How can I fix this?

ksgill 03-25-2005 07:55 AM

Does it happen with all the programs or just one or two particular ones? What program are you trying to run?

pfaendtner 03-25-2005 09:44 AM

I run some computational chemistry software and in-house c-codes (ode solvers, etc). Pretty much anytime I've got something backgrounded and exit my shell it hangs...

visaris 03-25-2005 09:53 AM

Yeah, the shell is waiting for all the jobs to finish. I'm not sure how to get it to stop doing that. If you kill off all the jobs before you try an log out you shouldn't have any problems. Type jobs to list all the current jobs.
Code:

foo@bar foo $ jobs
[1]  Running                ddd &
[2]-  Running                gqview &
[3]+  Running                xmms &
foo@bar foo $

They bring them to the forgraound with "fg 1", "fg 2", "fg 3", etc, and kill them with ^C. You should be able to log out fine after that.

pfaendtner 03-25-2005 10:09 AM

The thing is I often run jobs in the background and logout because they take several days. We use 4 or 5 workstations for running code, etc and it's common to launch a job and then go work somewhere else. Typically I have two shells open then in another window I kill the ssh which has hung. It gets the job done, I just think there has to be a better way.

ralvez 03-25-2005 10:34 AM

The solution to your problem is a command called: screen
Say that you want to run something in a particular system like a heavy duty number crunching program and that it would take too long to wait for it to finish ... sounds like your case?
OK. This is what you do:
1.Log over SSH into the system
2. Issue the command screen -t number_crunching
3. Start the program that does all the magic with the numbers
4. press Ctrl+a
5. press d
6. log off that machine

When you are ready (say 1 or 2 hrs later) you log in again into that system (using ssh) then your type:
screen -p number_crunching -r
and you are back to the exact same thread you left off earlier, but you see all messages that the math program wrote to the console and if it is done working you will see it, otherwise, if it needs to for for a bit more you type Ctrl+a and press "d" again and let it "cook" for a bit more.

I must say this program rocks ! I use it all the time.

Hope this will help you too.

Rick


All times are GMT -5. The time now is 10:12 AM.