Is it possible and if so how do I:
- Start a
/bin/bash
process that is not bound to a terminal from a terminal? Hence, a shell process that shows up in the process tree asinit -- bash
. (Shells usually have the process tree structureterminal-emulator-of-your-choosing -- bash
) - Start a
/bin/bash
process not bound to a terminal that has as its child another process e.g. a browser likefirefox
from a shell session in a terminal? Hence, a shell process with a child that shows up in the process tree asinit -- bash -- firefox
. - It is easy to get
init -- firefox
directly from the shell via something along the lines ofexec firefox & exit
or/bin/bash -c firefox & exit
.
(This question is part of a series of related questions that first enabled me to formulate these questions precisely (cf. How to "correctly" start an application from a shell and Is reparenting from the shell possible?). The three questions have been formulated and discussed partially in the comments of the two former questions but as I see it not been answered. Furthermore, they do seem more appropriate as short question in their own right not suited for discussion in comments.)
setsid sh -c 'firefox&' <> /dev/null >&0 2>&0
(note that it makes it immune to SIGINTs) – Stéphane Chazelas Aug 28 '14 at 13:39setsid bash -c 'firefox; exit'
if you actually wantinit -- bash -- firefox
not connected to a terminal (setsid sh -c 'bash -c "firefox; exit" &'
to make sure thatbash
doesn't get control of a terminal if it ever opens one). – Stéphane Chazelas Aug 28 '14 at 13:53setsid
making the process immune to SIGINTS worries me. Actually the link you provided contains a command that does exactly what I want:(trap '' HUP; command) &
. Do you have an opinion on that (possible problems etc.?) – lord.garbage Aug 28 '14 at 13:59setsid
commands make the process immune to SIGINTs? If i usekill -15 PID-of-firefox
on the instances of firefox I started with your commands they exit cleanly. – lord.garbage Aug 28 '14 at 14:12(trap '' HUP; command) &
still results in a process bound to a terminal (at least until the interactive shell you started it from exits). Is that what you want? – Mark Plotnick Aug 28 '14 at 17:07(trap '' HUP; command) & exit
. – lord.garbage Aug 28 '14 at 17:42setsid
making processes immune to SIGINT (though it does make it immune to CTRL-C by detaching from the terminal). It's running a job in background from a subshell that does. Thesetsid()
system call is the only way one can detach from a terminal. – Stéphane Chazelas Sep 01 '14 at 09:02mksh
has that feature built in. Runmksh -T/dev/tty10
to open one on that tty,mksh -T- -c 'command; command; …'
to run dæmonised. (Full disclosure: I’m themksh
developer.) – mirabilos Dec 23 '14 at 18:52