Question

Sometimes I want to condition on the existence of a TID (thread identifier) so that I can see when it finishes. For example, suppose I make a large file copy in nautilus. And then I realize it's going to take 3 hours (suppose I realize too late and I don't want to cancel and do it form the CL). I would like to tell my computer to shutdown after Nautilus finishes the copy. If there is big I/O (as of course there will be in a file copy), I can use iotop and that nicely gives me the TID. How can I condition on that TID finishing? Also, suppose a thread isn't doing a lot of I/O. How can I get it's TID? I know how to get PIDs (e.g. ps or cat /proc/<PID>/status) and when there's only one thread the TID is the same as the PID, but what if there is more than one thread?

Here is what I do to condition on a PID:

while ps aux | grep [2]9228 > /dev/null; do sleep 20s; done; echo "Process Finished"
Was it helpful?

Solution

I assume this question is specific and not in general.

/proc/<PID>/task/ contains a list of directories, one for each thread in the given process.

OTHER TIPS

You can also get the TID with ps.

Script-friendly command (only TIDs, one per line, no header line):

ps -L --pid <PID> -o tid=

or, for more verbosity:

ps -L --pid <PID> -O tid
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top