5

If I execute the following command in LXTerminal:

gnome-terminal &

gnome-terminal gets opened. But as soon as I close the LXTerminal, gnome-terminal will be closed as well because it's a child process. Is there any way to open the second process independently?

slm
  • 369,824
B Faley
  • 4,343
  • 11
  • 39
  • 48

2 Answers2

7

It's not possible to start a process without it being the child. When you execute an external command, under the hood the shell calls fork() followed by execvp(). You can prevent it from getting killed when the parent shell dies.

One way is to use nohup:

nohup gnome-terminal &

Another option if you are using bash is to disown the process:

gnome-terminal & disown
jordanm
  • 42,678
-1

Yes just try to open this as follow.

$ sudo gnome-terminal &

So that both the terminals are available to you for work. But remember not to close the Parent terminal, as it will close the child terinal.

I is possible with nohup.

$ nohup gnome-terminal &
$ exit
Aditya
  • 109
  • 4
    I think you missed the point of the question and even added an unnecessary sudo. – jordanm Nov 16 '13 at 05:55
  • It is not possible to open child process independently. You are asking to kill the parent process, how can a child process will survive Meysam. – Aditya Nov 16 '13 at 06:00
  • "It is not possible to open child process independently". Are you definitely sure it's not possible? – B Faley Nov 16 '13 at 06:02
  • Yes i am definitely sure as per my knowledge. You can use that terminal but can not close that terminal. – Aditya Nov 16 '13 at 06:04
  • @Meysam - all processes are children, with the exception of init. – jordanm Nov 16 '13 at 06:05
  • Yes. please try with nohup command. May be it is possible. About init, it is a process that runs background. You can not kill init, unless you want to shut down your machine. – Aditya Nov 16 '13 at 06:06
  • Go through this link http://www.cyberciti.biz/tips/nohup-execute-commands-after-you-exit-from-a-shell-prompt.html It is possible, but about init, all processes are children with the exception of init as Jordanm said. – Aditya Nov 16 '13 at 07:13