- 论坛徽章:
- 7
|
之前一直没有用过strace命令,今天用的时候用"strace -p 进程id“ 发现只列出来主线程的系统调用,其他的列不出来。然后做了一个例子,非常简单。- #include <stdio.h>
- #include <unistd.h>
- #include <pthread.h>
- void* runner(void* param)
- {
- while (1)
- {
- sleep(1);
- printf("........\n");
- }
- }
- int main()
- {
- pthread_t pid;
- int s = pthread_create(&pid, NULL, runner, NULL);
-
- while (1)
- {
- sleep(2);
- }
- return 0;
- }
复制代码 这时用strace -p 进程id -f 才可以列出创建线程中的系统调用。
man strace 发现
-f Trace child processes as they are created by currently traced processes as a result of the fork(2) system call.
On non-Linux platforms the new process is attached to as soon as its pid is known (through the return value of fork(2) in the parent process).
This means that such children may run uncontrolled for a while (especially in the case of a vfork(2)), until the parent is scheduled again to
complete its (v)fork(2) call. On Linux the child is traced from its first instruction with no delay. If the parent process decides to wait(2)
for a child that is currently being traced, it is suspended until an appropriate child process either terminates or incurs a signal that would
cause it to terminate (as determined from the child’s current signal disposition).
英语不大好,大体的意思应该是追踪当前进程fork出来的子进程。没有研究过pthread的源码,难道pthread是通过fork实现的?! |
|