Get process id

I bet there’s an easier way to do this.

I need to get the pid of the command that started a process-typically ‘sudo shutdown’

I started the shutdown with:

sudo shutdown -h +120

The command to get just the pid is:

ps -ef | grep 'sudo shutdown -h' | grep -v 'grep' | awk '{print $2}'


ps ax | grep 'sudo shutdown -h' | grep -v 'grep' | awk '{print $1}'

-v excludes our current command from results.

The awk command prints the labelled coloumn of output only.

You are reading this post on Joel G Mathew’s tech blog. Joel's personal blog is the Eyrie, hosted here.