LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Terminals and Background Processes (https://www.linuxquestions.org/questions/linux-general-1/terminals-and-background-processes-500383/)

dfego 11-10-2006 12:38 PM

Terminals and Background Processes
 
I'm not sure if this is new behavior, or just something I've never encountered, but I found it weird. I run Gentoo with Fluxbox, and have mrxvt as my terminal. When I type in a command with an & at the end,to make it a background process, it seems to work, but the process ends when I close the terminal. Should this be happening? I don't want it to happen, and there must be a way to work around it, so any help would be appreciated.

matthewg42 11-10-2006 01:01 PM

Yes it's normal. When you close a terminal, all child processes receive the HUP signal (Hand UP). The default behavior for most programs is to terminate when this signal is received, although it's possible for a programmer to write a program to ignore it.

There are a few ways you can prevent this.

1. prefix your command with nohup
2. run your programs in screen. This has the advantage that you can re-attach to them from another session if necessary.

I'm sure there are more too, but these two spring to mind.

soggycornflake 11-11-2006 08:39 AM

Quote:

(Hand UP)
I assume that's a typo? It is of course 'Hang UP', presumably a left over from dialup serial terminal days.

You can also use 'disown <job>' after a process has started, which is the equivalent of prefixing the command with 'nohup'. disown without arguments will disown all jobs (use bg first if the're stopped, or you'll need to do a kill -CONT <pid>).

However, as matthewg42 says, the best solution is screen, since then you can reattach later.

matthewg42 11-11-2006 08:52 AM

Quote:

Originally Posted by soggycornflake
I assume that's a typo? It is of course 'Hang UP', presumably a left over from dialup serial terminal days.

Oops, yes. *blush*
Quote:

Originally Posted by soggycornflake
You can also use 'disown <job>' after a process has started, which is the equivalent of prefixing the command with 'nohup'. disown without arguments will disown all jobs (use bg first if the're stopped, or you'll need to do a kill -CONT <pid>).

However, as matthewg42 says, the best solution is screen, since then you can reattach later.

Ooh, I didn't know about disown. Excellent!


All times are GMT -5. The time now is 01:04 AM.