I was trying to get pid of process I ran with setsid
and which ought to run in background like this:
test.sh:
#/bin/bash
setsid nohup ./my_program &
echo $!
if I run ./test.sh
it will print a pid of my_program
process and it's exactly what I need. But if run this commands one by one in my shell like this:
$ setsid nohup ./my_program &
$ echo $!
It will give me a pid of setsid
command (or may be something else, but it almost all times gives me pid of my_program
minus one).
What is happening here? Why results of commands I ran in terminal by myself differs from results of test.sh
script?
Btw, may be you know some easy way of process which I started with setsid and which I need to run in background?