Reputation: 339
I want to know the PID of the last executed command. I saw this a lot:
$ command &
$ pid=$!
But I'm searching for the same thing without running the command in the background.
Upvotes: 8
Views: 6004
Reputation: 21
You can use the following construction in scripts:
PID=`sh -c "echo $$; exec your_command -with-arguments"`
echo $PID
Upvotes: 2