How to get PID of the background process

It is a very simple operation that can be effectively used inside shell scripts.

Use $! special parameter to get the process ID of the most recently executed background command.

$ find . -name 2014-* -fprint articles.2014 &
[1] 1634
$ echo $!
1634

See Special Parameters section of the bash manual page for further reference.

As a side note, I will mention How to open manual page at the specific page section blog post I wrote more than a year ago.

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu