How do I find threads that belong to the same process in Linux-Collection of common programming errors
Actually, you don’t need task_struct
at all.
See my gist for a example code on printing the threads of a process with a given pid.
Reference
Type man proc
at the command line (online version), and find the entry for /proc/[pid]/task
.
Quoting from the man page:
This is a directory that contains one subdirectory for each thread in the process. The name of each subdirectory is the numerical thread ID ([tid]) of the thread.
Note that one of the subdirectories in /proc/[pid]/task
is whatever [pid]
is (the pid of the program you’re inspecting).
You can then gather other information using the pseudo-files in the directory /proc/[pid]/task/[tid]
for each thread pid [tid]
.
Without C Code
ps -mo THREAD -p
should work.