2018-07-17 strace

【转】用strace查找进程卡死原因

针对printf有效
From: https://blog.csdn.net/wwyyxx26/article/details/51510868

sudo strace -o out.strace -e trace=write -s 200 -f -p 1648

  • version 1
 8  #include
 9
10
11  int main()
12  {
13          printf("Enter main for systrace\n");
14          fflush(stdout);
15
16          while(1) {
17
18                  sleep(1);
19                  printf("i am in systrace\n");
20          }
21
22          return 0;
23  }

$ sudo strace -o out.starce -e trace=write -s 200 -f -p 3576

$ cat -n out.starce

 1  3576  write(1, "i am in systrace\n", 17) = 17
 2  3576  write(1, "i am in systrace\n", 17) = 17
 3  3576  write(1, "i am in systrace\n", 17) = 17
 4  3576  write(1, "i am in systrace\n", 17) = 17
 5  3576  write(1, "i am in systrace\n", 17) = 17
 6  3576  write(1, "i am in systrace\n", 17) = 17
 7  3576  write(1, "i am in systrace\n", 17) = 17
 8  3576  write(1, "i am in systrace\n", 17) = 17
 9  3576  write(1, "i am in systrace\n", 17) = 17
10  3576  write(1, "i am in systrace\n", 17) = 17
11  3576  write(1, "i am in systrace\n", 17) = 17
12  3576  write(1, "i am in systrace\n", 17) = 17
13  3576  write(1, "i am in systrace\n", 17) = 17
14  3576  write(1, "i am in systrace\n", 17) = 17
15  3576  write(1, "i am in systrace\n", 17) = 17

  • version 2
 8  #include
 9
10
11  int main()
12  {
13          int count = 0;
14
15          printf("Enter main for systrace\n");
16          fflush(stdout);
17
18          while(1) {
19
20                  sleep(1);
21                  printf("i am in systrace %d\n", count++);
22          }
23
24          return 0;
25  }

$ sudo strace -o out.starce -e trace=write -s 200 -f -p 3628

$ cat -n out.starce

 1  3628  write(1, "i am in systrace 15\n", 20) = 20
 2  3628  write(1, "i am in systrace 16\n", 20) = 20
 3  3628  write(1, "i am in systrace 17\n", 20) = 20
 4  3628  write(1, "i am in systrace 18\n", 20) = 20
 5  3628  write(1, "i am in systrace 19\n", 20) = 20
 6  3628  write(1, "i am in systrace 20\n", 20) = 20
 7  3628  write(1, "i am in systrace 21\n", 20) = 20
 8  3628  write(1, "i am in systrace 22\n", 20) = 20
 9  3628  write(1, "i am in systrace 23\n", 20) = 20
10  3628  write(1, "i am in systrace 24\n", 20) = 20
11  3628  write(1, "i am in systrace 25\n", 20) = 20
12  3628  write(1, "i am in systrace 26\n", 20) = 20
13  3628  write(1, "i am in systrace 27\n", 20) = 20
14  3628  write(1, "i am in systrace 28\n", 20) = 20
15  3628  write(1, "i am in systrace 29\n", 20) = 20
16  3628  write(1, "i am in systrace 30\n", 20) = 20
17  3628  write(1, "i am in systrace 31\n", 20) = 20

你可能感兴趣的:(2018-07-17 strace)