I have the following but I'm worried about $!
being overwritten prior to the echo command taking place. How do you guys recommend going about this?
sleep 100 & >/dev/null ; echo $! >sleep.pid
Bash is designed such that it cannot happen as you've described it. The value of $!
in one session is the pid of the last backgrounded process in that particular session.
$!
under other instances of bash. I'm quite certain that the value of$!
in one session is the pid of the last backgrounded process in that particular session.