a.sh
:
#!/bin/sh -eu
docker run --rm -v $PWD/b.sh:/b.sh alpine ./b.sh
b.sh
:
#!/bin/sh -eux
apk add dcron procps
ps -eHo sess,pgrp,ppid,pid,comm,args
exec crond -df
:r!./a.sh
...
+ ps -eHo sess,pgrp,ppid,pid,comm,args
SESS PGRP PPID PID COMMAND COMMAND
1 1 0 1 b.sh /bin/sh -eux ./b.sh
1 1 1 10 ps ps -eHo sess,pgrp,ppid,pid,comm,args
+ exec crond -df
setpgid: Operation not permitted
Without exec
it succeeds. Apparently it happens because dcron
calls setpgid()
, but with exec
it's the session leader.
EPERM An attempt was made [...] to change the process group ID of a session leader (setpgid(), setpgrp()).
https://man.archlinux.org/man/core/man-pages/setpgid.2.en#ERRORS