找到进程所有者的方法(无需使用 ps 命令)。

huangapple go评论80阅读模式
英文:

how to find owner of a process without ps

问题

Running nginx alpine image. ps is not installed and do not have permission to install ps using apt-get. I have the pid of process. Is there any way I can find out who the owner of process is ?

在这种情况下,我想找出谁在运行nginx主进程。

英文:

Running nginx alpine image. ps is not installed and do not have permission to install ps using apt-get. I have the pid of process. Is there any way I can find out who the owner of process is ?

In this case, I want to figure out who is running nginx master process.

答案1

得分: 6

使用 ls 命令在 proc 目录中查找进程所有者

ls -ld /proc/816

如果你有 stat 命令,你可以使用漂亮的格式显示只有所有者:

stat -c '%U' /proc/775
avahi

奖励:打印你的用户名而不查看 $USER

stat -c '%U' /proc/$$
英文:

Use ls to find the process owner in the proc directory

ls -ld /proc/816

If you have stat you can display just the owner with fancy formatting:

stat -c '%U' /proc/775
avahi

Bonus: print your user name without looking at $USER

stat -c '%U' /proc/$$

答案2

得分: 2

你可以在/proc/YOUR_PROCESS_ID/status中找到与进程相关的所有信息,其中YOUR_PROCESS_ID是你的进程的PID。

因此,你可以通过运行类似以下命令来获取进程的所有者:

cat /proc/YOUR_PROCESS_ID/status | grep "Uid" | cut -f 2 | id -nu
英文:

You can find all the information relative to a process in /proc/YOUR_PROCESS_ID/status where YOUR_PROCESS_IDis the PID of your process.

Therefore, you could get the owner of the process by simply running something like this:

cat /proc/YOUR_PROCESS_ID/status | grep "Uid" | cut -f 2 | id -nu

答案3

得分: 2

你可以使用 docker top 命令来获取有关在 Docker 容器内部运行的所有进程的详细信息

语法

docker top <容器ID或名称>
英文:

You can use docker top command to get details about all the processes running inside a docker container

Syntax

docker top &lt;container ID or name&gt;

答案4

得分: 0

如何从活动进程列表中检查?

top

如果要查找特定进程名称:

top | grep nginx
英文:

How about checking from active processes list?

top

If looking for specific process name:

top | grep nginx

huangapple
  • 本文由 发表于 2020年1月4日 00:39:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/59582151.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定