I show the command first:
Code:
see@linux-ub7v:~> setsid sleep 5 & echo "$! setsid"; sleep 1; ps -eo pid,args | grep sleep | grep -v grep
12498 setsid
12502 sleep 5
see@linux-ub7v:~> killall sleep
see@linux-ub7v:~> bash -c 'setsid sleep 5 & echo "$! setsid"; sleep 1; ps -eo pid,args | grep sleep | grep -v grep'
12507 setsid
12507 sleep 5
see@linux-ub7v:~> setsid --version
setsid from util-linux 2.21.2
The first commands were executed by an interactive shell, we can see there are the different pid between setsid and sleep,
but the third commands, I put them into a non-interactive shell, and then, we can see there are the same pid of setsid and sleep.
I guess setsid in first command may be "fork -> exec sleep by child -> parent exit" and setsid in third command just do "exec sleep" directly.
If I am right, why does setsid have a different behavior between interactive shell and non-interactive shell ?
Thanks in advance!