【问题标题】:How to see system call that executed in current time by process?如何查看进程在当前时间执行的系统调用?
【发布时间】:2017-03-08 17:16:47
【问题描述】:

Linux 实用程序“strace”显示在运行 strace 后启动的系统调用列表。如何按进程查看当前时刻运行的系统调用?在 strace 开始之前。

【问题讨论】:

  • 你打开一个控制台窗口并开始输入 /usr/sbin.... dang 当前时间已经结束,已经是下一个时刻了!错过了!下次比当前时间早一点开始!
  • 我同意。我将重新提出我的问题:如何查看进程当前正在执行的系统调用?

标签: linux strace


【解决方案1】:

proc 提供了一些关于内核当前正在“为”进程“做什么”的信息
/proc/${pid}/syscall /proc/${pid}/stack

更多信息:

【讨论】:

    【解决方案2】:

    假设您知道进程的 PID,您可以简单地使用 strace 实时跟踪所有系统调用。

    strace -p PID

    【讨论】:

      【解决方案3】:

      您可以使用ps

      ps -p PID_OF_PROC -ocmd,stat,wchan
      

      wchan 是这里的关键。来自man ps

      wchan WCHAN 进程正在休眠的内核函数的名称,如果进程正在运行,则为“-”,或者 "*" 如果进程是多线程的并且 ps 不显示线程。


      过程状态代码 以下是 s、stat 和 state 输出说明符(标题“STAT”或“S”)将显示以描述的不同值 进程的状态:

                 D    uninterruptible sleep (usually IO)
                 R    running or runnable (on run queue)
                 S    interruptible sleep (waiting for an event to complete)
                 T    stopped by job control signal
                 t    stopped by debugger during the tracing
                 W    paging (not valid since the 2.6.xx kernel)
                 X    dead (should never be seen)
                 Z    defunct ("zombie") process, terminated but not reaped by its parent
      
        For BSD formats and when the stat keyword is used, additional characters may be displayed:
      
                <    high-priority (not nice to other users)
                N    low-priority (nice to other users)
                L    has pages locked into memory (for real-time and custom IO)
                s    is a session leader
                l    is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)
                +    is in the foreground process group
      

      【讨论】:

      • 有用,但内核函数和系统调用不一定相同。
      • @GL2014 没错,但这就是你能从 ps 得到的全部。
      • PS:刚刚在这个帖子中看到了接受的答案,看起来这就是要走的路
      • wchan 是 /proc/pid/stack 中显示的顶部帧(当进程未处于 TASK_RUNNING 状态时)
      猜你喜欢
      • 2012-05-10
      • 2016-07-19
      • 2013-05-20
      • 2014-09-10
      • 1970-01-01
      • 1970-01-01
      • 2012-10-31
      • 2013-05-21
      • 2013-10-03
      相关资源
      最近更新 更多