I want to spawn a process and run it at the top level so that when the shell exits, the process keeps running.
I had mistakenly thought that nohup would do this, but when I exit from the shell (the shell is a lxc container and I ssh into that) and re-enter, the process is gone.
It seems (looking at pstree) that the process is still under the invoking shell even with nohup or disown.
I tried a few options and setsid seems to work - but am I doing something wrong with nohup here ?
$ cat myproc
sleep 1234
$ myproc &
$ pstree -a | grep -B 3 "1234" | grep -v grep
|-screen
| |-bash -ls
| | |-bash -ls
| | | `-sleep 1234
$ nohup myproc &
$ pstree
|-screen
| |-bash -ls
| | |-pstree -a
| | `-sh ./myproc
| | `-sleep 1234
$ myproc &
$ disown $!
$ pstree -a | grep -B 3 "1234" | grep -v grep
|-screen
| |-bash -ls
| | |-bash -ls
| | | `-sleep 1234
$ setsid myproc &
|-sh ./myproc
| `-sleep 1234
success. But why did nohup not achieve the same? Is there a way to use nohup more correctly?