LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   A couple of questions about command line usage (https://www.linuxquestions.org/questions/linux-general-1/a-couple-of-questions-about-command-line-usage-588930/)

MasterOfTheWind 10-02-2007 01:00 PM

A couple of questions about command line usage
 
Hi!

I've got a couple questions about command line usage:

1) If I run an xterm, then run an app from it, say firefox, forking the process at the same time ( firefox & ); I will not be able to terminate this xterm without terminating firefox at the same time. Is it possible to alter this behaviour so that it is possible to close the terminal without closing the program ran from it?

2) Is it possible to suppress *all* output from a program? The standard "> /dev/null" does not seem to be removing all the output in all conditions.

Thanks in advance ;)

uselpa 10-02-2007 01:32 PM

Quote:

Originally Posted by MasterOfTheWind (Post 2910764)
1) If I run an xterm, then run an app from it, say firefox, forking the process at the same time ( firefox & ); I will not be able to terminate this xterm without terminating firefox at the same time. Is it possible to alter this behaviour so that it is possible to close the terminal without closing the program ran from it?

Says who? Just tested it, works well.

Quote:

Originally Posted by MasterOfTheWind (Post 2910764)
2) Is it possible to suppress *all* output from a program? The standard "> /dev/null" does not seem to be removing all the output in all conditions.

foo &> /dev/null

Nylex 10-02-2007 01:43 PM

Quote:

Originally Posted by uselpa (Post 2910799)
Says who? Just tested it, works well.

While this works for Firefox, the behaviour isn't universal. gxine for example closes when the term is closed, as does Amarok.

FWIW, if you need to keep a console program running after closing the terminal, look at Screen (you should have it installed).

MasterOfTheWind 10-02-2007 01:46 PM

Quote:

Originally Posted by uselpa (Post 2910799)
Says who? Just tested it, works well.

Doesn't work for me unfortunately (any programs that are run that way are shown as child processes of bash, which in turn is a child of xterm) :( Don't really know what the problem is though.

Quote:

Originally Posted by uselpa (Post 2910799)
foo &> /dev/null

Thanks ^^

MasterOfTheWind 10-02-2007 01:49 PM

Quote:

Originally Posted by Nylex (Post 2910814)
While this works for Firefox, the behaviour isn't universal. gxine for example closes when the term is closed, as does Amarok.

For me this doesn't even work with firefox :(

Quote:

Originally Posted by Nylex (Post 2910814)
FWIW, if you need to keep a console program running after closing the terminal, look at Screen (you should have it installed).

Thanks, I'll check it out :D

kotnik 10-02-2007 01:51 PM

Some apps detach themselves from shell, as Firefox does. Firefox forks into firefox-bin and then it disappears.

uselpa 10-02-2007 02:31 PM

I've tested with Firefox, Thunderbird, and gxine, and they all continue to work, although the parent process changes. Maybe this is a behavior of Konsole, as opposed to plain xterm?

Code:

(shell 1)
pu@slackw:~$ gxine &
[1] 5118

(shell 2)
pu        5084  3343  1 21:25 ?        00:00:00    konsole [kdeinit] --ls
pu        5096  5084  0 21:26 pts/3    00:00:00      -bash
pu        5146  5096  0 21:26 pts/3    00:00:00        ps -efH
pu        5107  5084  0 21:26 pts/4    00:00:00      -bash
pu        5118  5107  7 21:26 pts/4    00:00:01        gxine

(shell 1)
Ctrl-D

(shell 2)
pu        5118    1  4 21:26 ?        00:00:08  gxine


uselpa 10-02-2007 02:33 PM

BTW - you could also try preceding your command with "nohup".

MasterOfTheWind 10-02-2007 02:40 PM

Quote:

Originally Posted by uselpa (Post 2910875)
Maybe this is a behavior of Konsole, as opposed to plain xterm?

Hmm... I tested konsole too, and it seems to give me the same result. Probably something with my bash-configuration or something then :)


Quote:

Originally Posted by uselpa (Post 2910875)
BTW - you could also try preceding your command with "nohup".

Thanks, that works perfectly :D

trashbird1240 10-02-2007 03:58 PM

No need to resort to Screen for this (although you should look into it
anyway). What you want is "disown." For example, if I start a
process from the shell, I can then just enter "disown".

Which shell are you using? You may have more than one available.
Check the documentation for the shell you're using under "job
control."

Joel

uselpa 10-02-2007 04:03 PM

"disown" or "disown -h" should to the trick as well, as should "shopt -u huponexit". Actually this has the whole story, for bash at least. Lookup "disown", "huponexit" and "SIGHUP".

kotnik 10-04-2007 11:52 AM

Open /usr/bin/firefox. And see. It is not Firefox web browser, it's a shell script. I told you, it detachs firefox-bin from terminal. Do a pstree with Firefox started and see who's its parent. When parent dies, children die - no exception.

uselpa 10-04-2007 12:45 PM

Quote:

Originally Posted by kotnik (Post 2913194)
When parent dies, children die - no exception.

That's obviously wrong, see bash as an example.

kotnik 10-04-2007 01:03 PM

Yeah, it's wrong... I apologize :) It was the heat of the moment :)

uselpa 10-04-2007 01:20 PM

No worries - I learned I lot myself between post#2 and post#11 :-)


All times are GMT -5. The time now is 07:47 AM.