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

Subscribe to My Newsletter

The latest programming-related news, articles and resources - sent to your inbox monthly. Unsubscribe anytime.