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.
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).
You can use -o option to specify a file which saves strace 's output: # strace -o log. txt ls log.
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 .
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With