This question is closely related to How to correctly start an application from a shell but tries to tackle a more specific problem. How can I spawn an application from a shell and thereby making it a child of another process. Here is what I mean exemplified with two graphics:systemd-+-acpid        |-bash---chromium-+-chrome-sandbox---chromium-+-chrome-sandbox---nacl_helper        |                 |                           `-chromium---5*[chromium-+-{Chrome_ChildIOT}]        |                 |                                                    |-{Compositor}]        |                 |                                                    |-{HTMLParserThrea}]        |                 |                                                    |-{OptimizingCompi}]        |                 |                                                    `-3*[{v8:SweeperThrea}]]        |                 |-chromium        |                 |-chromium-+-chromium        |                 |          |-{Chrome_ChildIOT}        |                 |          `-{Watchdog}        |                 |-{AudioThread}        |                 |-3*[{BrowserBlocking}]        |                 |-{BrowserWatchdog}        |                 |-5*[{CachePoolWorker}]        |                 |-{Chrome_CacheThr}        |                 |-{Chrome_DBThread}        |                 |-{Chrome_FileThre}        |                 |-{Chrome_FileUser}        |                 |-{Chrome_HistoryT}        |                 |-{Chrome_IOThread}        |                 |-{Chrome_ProcessL}        |                 |-{Chrome_SafeBrow}        |                 |-{CrShutdownDetec}        |                 |-{IndexedDB}        |                 |-{LevelDBEnv}        |                 |-{NSS SSL ThreadW}        |                 |-{NetworkChangeNo}        |                 |-2*[{Proxy resolver}]        |                 |-{WorkerPool/1201}        |                 |-{WorkerPool/2059}        |                 |-{WorkerPool/2579}        |                 |-{WorkerPool/2590}        |                 |-{WorkerPool/2592}        |                 |-{WorkerPool/2608}        |                 |-{WorkerPool/2973}        |                 |-{WorkerPool/2974}        |                 |-{chromium}        |                 |-{extension_crash}        |                 |-{gpu-process_cra}        |                 |-{handle-watcher-}        |                 |-{inotify_reader}        |                 |-{ppapi_crash_upl}        |                 `-{renderer_crash_}        |-2*[dbus-daemon]        |-dbus-launch        |-dhcpcd        |-firefox-+-4*[{Analysis Helper}]        |         |-{Cache I/O}        |         |-{Cache2 I/O}        |         |-{Cert Verify}        |         |-3*[{DOM Worker}]        |         |-{Gecko_IOThread}        |         |-{HTML5 Parser}        |         |-{Hang Monitor}        |         |-{Image Scaler}        |         |-{JS GC Helper}        |         |-{JS Watchdog}        |         |-{Proxy R~olution}        |         |-{Socket Thread}        |         |-{Timer}        |         |-{URL Classifier}        |         |-{gmain}        |         |-{localStorage DB}        |         |-{mozStorage #1}        |         |-{mozStorage #2}        |         |-{mozStorage #3}        |         |-{mozStorage #4}        |         `-{mozStorage #5}        |-gpg-agent        |-login---bash---startx---xinit-+-Xorg.bin-+-xf86-video-inte        |                               |          `-{Xorg.bin}        |                               `-dwm-+-dwmstatus        |                                     `-xterm---bash-+-bash        |                                                    `-pstree        |-systemd---(sd-pam)        |-systemd-journal        |-systemd-logind        |-systemd-udevd        |-wpa_actiond        `-wpa_supplicantThe process tree shows chromium and firefox as children of the init process that starts at boot and has PID 1. But what I want to achieve is to start firefox and chromium as children of dwm. Hence, I want a similar behaviour to what you can see under the weston part of the following process tree where firefox has weston-desktop as its parent:systemd-+-acpid        |-bash---chromium-+-chrome-sandbox---chromium-+-chrome-sandbox---nacl_helper        |                 |                           `-chromium-+-3*[chromium-+-{Chrome_ChildIOT}]        |                 |                                      |             |-{Compositor}]        |                 |                                      |             |-{HTMLParserThrea}]        |                 |                                      |             |-{OptimizingCompi}]        |                 |                                      |             `-3*[{v8:SweeperThrea}]]        |                 |                                      `-4*[chromium-+-{Chrome_ChildIOT}]        |                 |                                                    |-{CompositorRaste}]        |                 |                                                    |-{Compositor}]        |                 |                                                    |-{HTMLParserThrea}]        |                 |                                                    |-{OptimizingCompi}]        |                 |                                                    `-3*[{v8:SweeperThrea}]]        |                 |-{AudioThread}        |                 |-3*[{BrowserBlocking}]        |                 |-{BrowserWatchdog}        |                 |-5*[{CachePoolWorker}]        |                 |-{Chrome_CacheThr}        |                 |-{Chrome_DBThread}        |                 |-{Chrome_FileThre}        |                 |-{Chrome_FileUser}        |                 |-{Chrome_HistoryT}        |                 |-{Chrome_IOThread}        |                 |-{Chrome_ProcessL}        |                 |-{Chrome_SafeBrow}        |                 |-{Chrome_SyncThre}        |                 |-{CrShutdownDetec}        |                 |-{IndexedDB}        |                 |-{NSS SSL ThreadW}        |                 |-{NetworkChangeNo}        |                 |-2*[{Proxy resolver}]        |                 |-{WorkerPool/2315}        |                 |-{WorkerPool/2316}        |                 |-{WorkerPool/2481}        |                 |-{chromium}        |                 |-{extension_crash}        |                 |-{gpu-process_cra}        |                 |-{handle-watcher-}        |                 |-{inotify_reader}        |                 |-{renderer_crash_}        |                 `-{sandbox_ipc_thr}        |-2*[dbus-daemon]        |-dbus-launch        |-dhcpcd        |-gpg-agent        |-login---bash---startx---xinit-+-Xorg.bin-+-xf86-video-inte        |                               |          `-{Xorg.bin}        |                               `-dwm-+-dwmstatus        |                                     `-xterm---bash        |-login---bash---weston-launch---weston-+-Xwayland---4*[{Xwayland}]        |                                       |-weston-desktop--+-firefox-+-firefox        |                                       |                 |         |-4*[{Analysis Helper}]        |                                       |                 |         |-{Cache2 I/O}        |                                       |                 |         |-{Cert Verify}        |                                       |                 |         |-{DNS Resolver #1}        |                                       |                 |         |-{DNS Resolver #2}        |                                       |                 |         |-2*[{DOM Worker}]        |                                       |                 |         |-{Gecko_IOThread}        |                                       |                 |         |-{HTML5 Parser}        |                                       |                 |         |-{Hang Monitor}        |                                       |                 |         |-{Image Scaler}        |                                       |                 |         |-{ImageDecoder #1}        |                                       |                 |         |-{ImageDecoder #2}        |                                       |                 |         |-{ImageDecoder #3}        |                                       |                 |         |-{JS GC Helper}        |                                       |                 |         |-{JS Watchdog}        |                                       |                 |         |-{Socket Thread}        |                                       |                 |         |-{Timer}        |                                       |                 |         |-{URL Classifier}        |                                       |                 |         |-{gmain}        |                                       |                 |         |-{localStorage DB}        |                                       |                 |         |-{mozStorage #1}        |                                       |                 |         |-{mozStorage #2}        |                                       |                 |         |-{mozStorage #3}        |                                       |                 |         |-{mozStorage #4}        |                                       |                 |         `-{mozStorage #5}        |                                       |                 `-weston-terminal---bash---pstree        |                                       `-weston-keyboard        |-systemd---(sd-pam)        |-systemd-journal        |-systemd-logind        |-systemd-udevd        |-tmux---bash        |-wpa_actiond        `-wpa_supplicantOne possible solution would be to use nsenter from util-linux. I could enter the namespace of the dwm process and fork a new firefox process which would then be the child of dwm. However, that seems like a lot of work. Is there some easier way to do this?
Is reparenting from the shell possible?
process;exec;namespace
You can not start a process as the child of the shell, and then reparent it so another process becomes it's parent.So you need to use a parent process that explicitly starts the children.init with PID 1 is an exception, processes can become it's child as it collects processes that lost their original parent process.(With upstart, there can be multiple init processes, they do not share the PID 1, but otherwise the roles are very similar.)(See also PR_SET_CHILD_SUBREAPER in man 2 prctl)