See/Count how many subshells a script has opened

Viewed 80

Im having a conundrum with a script (or possible wsl2 memory leak).

I'm running a large script (that takes 0.67 seconds to loop)

My issue is that the loop time is slowly increasing, and so is the memory usage, so from 0.67 seconds / 0.9gig memory to 1.20 seconds / 1.7gig after a few hours.

If I restart (stop/start), the speed goes up again and the memory usage goes down to 0.9 again..

I'm suspecting that my script is leaving running subshells, and I'm wondering if there's anyway to see how many subshells that's currently running?

oh, I'm running this on win10 Wsl2 Ubuntu

1 Answers

Run ps and show only parent process ids and process ids. Pipe the output to awk, setting a variable pid to a given parent process id. Where the first space delimited field (parent process id) is equal to the passed pid, print the process id (field 2)

ps -eo ppid,pid | awk -v pid=<pid> '$1==pid { print $2 }'
Related