简体   繁体   English

如何在Linux中从pid获取进程的路径或名称

[英]How to get the path or name of the process from pid in linux

I have implemented a sigaction(SIGTSTP, &act, NULL) signal handler from which I am able to get the pid of the process which is sending the signal. 我实现了一个sigaction(SIGTSTP, &act, NULL)信号处理程序,从中可以获取正在发送信号的进程的pid。 And with this pid I am trying to get the path of that process using the command 并使用此pid尝试使用以下命令获取该进程的路径

ls -l /proc/pid/exe

but it is showing message 但它显示消息

ls: /proc/23710/exe: No such file or directory

Even I am executing the command "ps" the process is not listed. 即使我正在执行命令“ ps”,该过程也未列出。 Can anybody tell me how to get the path or name of such process? 有人可以告诉我如何获取该过程的路径或名称吗?

You can get the command line of the process from pid, you can read the /proc/<pid>/cmdline : 您可以从pid获取进程的命令行,可以阅读/proc/<pid>/cmdline

   /proc/[pid]/cmdline
          This read-only file holds the complete command line for the
          process, unless the process is a zombie.  In the latter case,
          there is nothing in this file: that is, a read on this file
          will return 0 characters.  The command-line arguments appear
          in this file as a set of strings separated by null bytes
          ('\0'), with a further null byte after the last string.

From that, you may get the path or name of the process. 由此,您可以获取进程的路径或名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM