Shell: Get the PID of the last command


2018-03-09

! shell variable holds the PID of the last executed command.

long-process &
[1] 589

Access it as $!:

echo $!

Assign it to a variable:

long-process & export LONG_PROCESS_PID=$!