Say I run time ./a.out
, then I can get the PID of time
by the variable $!
. But how do I get the PID of a.out
?
Of course, I could parse the output of ps
, but I want a more elegant solution.
I've checked man time
and couldn't find anything.
The closest I've gotten is time (sleep 10 & echo $!)
, but because of the fork, the time taken is basically 0 and not 10s as it should be.
Best Answer
By definition,
a.out
is a child process oftime
. Sotime
is the parent pid ofa.out
! here's a test where I replacea.out
withsleep 60
:(note: where
time
is actually a shell build-in, so the command above isbash
!)