[SOLVED] Slackware 13.37 - Start a program from Terminal
SlackwareThis Forum is for the discussion of Slackware Linux.
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.
When I was using Ubuntu, if I wanted to start a program from the command line, I would just append the "&" at the end of the command and it would spawn the program in a new process, so that I was free to continue using the terminal window or close it even (lets say putty for example, since I do use that).
Now in Slackware, when I do the same thing, it doesn't have the same effect. It starts the program sure, but the terminal is still somewhat tied up. I can continue using it, but any output the command might generate gets directed back to that terminal window, and if I was to close the terminal, the program shuts down.
How can I open programs via the command line, but have them completely in their own processes? At the moment I have to keep a few extra tabbed terminal windows open just so I can start the program and then all the output gets directed to the tabbed terminal where I don't see it.
If you have run the program in the background (by appending '&'), there's no reason why the process should shut down when you close the terminal, so I can't answer why this is happening to you; however, to prevent this, you could add 'nohup' to the beginning of your command, but skip outputting to /dev/null, as the nohup command causes the process to output to nohup.out (eg, nohup firefox & )
cheers,
Last edited by mrclisdue; 04-10-2012 at 07:31 AM.
Reason: clarification
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541
Rep:
This is where nohup and redirection come in handy.
Let's say you want to execute prog:
Code:
nohup prog 2>&1 &
This will start prog running, append the standard error to the standard output, and run in background. Any output from prog will be directed into a file, nohup.out (you can monitor what's going on with something like tail -f nohup.out). You can close the terminal window or log off entirely and the program will continue to run.
Note that, when you execute nohup, the process identification number (PID) will be displayed; you might want to write it down so you can conveniently kill the running program if necessary (you might want to, oh, go home or something) -- the program will not die until you kill it, the system is rebooted or there is a fatal error.
See the manual pages for nohup, kill and tail for more information.
If you have run the program in the background (by appending '&'), there's no reason why the process should shut down when you close the terminal
The reason is simple: Any program you launch from within the terminal is a child process of that terminal. If you kill the parent process you are automatically killing the children. Using the & is just telling the program to run in the background, it is some type of job control.
To prevent that the applications are closed you can use either nohup or disown.
If you kill the parent process you are automatically killing the children.
It is false, or at least not entirely truth. If one kills process it kills only this process, and never any children or parent. So behaviour "Child dies because parent dead" is problem of particular child.
I could be wrong, but I can't think of any occasion where a process I've backgrounded in a terminal is killed when I exit the terminal (other than when forwarding through ssh). Could you possibly provide an example?
Thanks for all the responses, and the nohup and > /dev/null options.
But for an example: I use putty for one of my work programs. It is a telnet based POS and parts system. I start it via the command line like [CODE]putty -load Parts\ Handler & [\CODE] because I have a few different versions I connect to. Now when I do this the program loads the proper session in the background, and I can use the terminal again. But if I close that terminal window, and I just did it again to confirm, my putty window (the child of that terminal) disappears.
I've never had this happen in Ubuntu and it seems weird that it would work differently in Slackware. I understand that certain children may die if the parent is killed, but I would think the terminal would be different since practically everything can be started from the command line. And putty isn't the only program that this happens to, it's just one that everyone here probably knows.
I could be wrong, but I can't think of any occasion where a process I've backgrounded in a terminal is killed when I exit the terminal (other than when forwarding through ssh). Could you possibly provide an example?
cheers,
Easy. I use Roxterm and zsh on my systems. For my example I created a simple script:
Code:
#!/bin/zsh
while true
do
date >> test.log
done
I open a terminal and execute that script in the background:
Code:
./test.sh &
For testing if the script is running I open a different terminal and launch
(I have an alias for grep to include the --color=auto option).
Now I close the terminal in which I have started the script (not even kill (SIGKILL), just close (SIGTERM)) and run the ps command again in the second terminal. Output:
I'm not trying to derail the thread, plus it is related to the OP, but why would a process ie.,$ firefox & *not* be killed when the original terminal is closed, but your script, for example, is? How would either scenario differ from launching the process from the 'run' box (alt-F2)?
Ah, then perhaps it's a difference between bash and zsh? I just tried your script and the process keeps running even when the original terminal is closed.
Alas, I tried the same test using zsh, and the processes shut down, as per your example, so it occurs with zsh but not with bash. Interesting, and I wonder why (but I won't be losing sleep over it!)
Ah, then perhaps it's a difference between bash and zsh? I just tried your script and the process keeps running even when the original terminal is closed.
Then it would be interesting to know which shell the OP uses.
It is false, or at least not entirely truth. If one kills process it kills only this process, and never any children or parent. So behaviour "Child dies because parent dead" is problem of particular child.
No - if a parent process is killed, a HUP (hang-up) signal is sent to ALL of it's child processes. The question is - what does the child process do. It may decide to ignore the HUP signal, in which case it will continue running. Do note that default is for programs to exit on HUP. Thus a program that does not do that will have to be explicitly programmed that way. It wouldn't surprise me if FireFox is compiled like that - I'm really not sure.
The other way for programs to ignore the death of a parent, is to "divorce" the parents first (my choice of words) - by becoming a daemon process. This is fairly complex, and requires deep Unix voodoo. And can really only be done by the original author (or another hacker if you have the source). Many programs offer a daemon mode from the command line - eg -D or -d or --daemon or -b (background).
I'm just using the default terminal that comes preinstalled with slackware 13.37. Nothing fancy.
So judging by the rest of this thread, I would assume that on Ubuntu, the terminal doesn't send the HUP signal to all child processes but Slackware does handle this properly, thus killing all children unless specifically divorced/disowned? Does that sound about right?
Seems to be so, but I neither have an install of Ubuntu nor would I know how to test if the terminal sends the SIGHUP to its child processes (well, I would know if my coding skills would be better).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.