Shell: Get the PID of the last command

2018-03-09 · 1 min read

! 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=$!

My Tech Newsletter

Get emails from me about programming & web development. I usually send it once a month