I'm using the
timeout utility inside a bash script to run a command for a given time (e.g.,
timeout -s SIGINT 500s ./my_script).
I want to monitor the process
myscript to see how much CPU/memory it uses (e.g. with the
htop -p <pid> command).
I know that when a process is started in background (with
&) I can get its pid programmatically by retrieving the
$! variable. The problem is that timeout spawns a new subprocess and with the
$! variable I get the "pid of timeout" and not the pid of myscript.
How can you retrive the pid of the subprocess spawned by timeout?