Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can we get thread id of thread in strace output of the multithreaded process?

just wondering if strace can give you a thread id of the thread who called the system call in case of multithreaded application. If it can be doable can please someone help me with the strace option i need to use for that.

like image 772
Anil Vishnoi Avatar asked Jan 21 '11 09:01

Anil Vishnoi


People also ask

How do I find the thread ID of a process in Linux?

In the GNU C Library implementation running on Linux, the process ID is the thread group ID of all threads in the process. You can get the process ID of a process by calling getpid . The function getppid returns the process ID of the parent of the current process (this is also known as the parent process ID).

How do you capture a strace output?

You can use -o option to specify a file which saves strace 's output: # strace -o log. txt ls log.

How does strace command work?

strace works by using the ptrace system call which causes the kernel to halt the program being traced each time it enters or exits the kernel via a system call. The tracing program (in this case strace ) can then inspect the state of the program by using ptrace .

Is thread ID unique in Linux?

The thread ID is used by the operating system to identify processes and threads. The thread id is unique globally but the users can capture the thread handle of the process thread through this id.


1 Answers

strace -f does that on linux. It prints pid but it's really a thread id - though if the straced program also forks and e.g. executes external commands, those will show up as well.

like image 120
nos Avatar answered Oct 20 '22 06:10

nos