Linux:如何查找守护进程和僵尸进程列表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17991095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:25:54  来源:igfitidea点击:

Linux: How to find the list of daemon processes and zombie processes

linuxunixlinux-kerneladminaix

提问by kris123456

I tried checking on Google, but I couldn't find much information related to the actual question.

我尝试在 Google 上查看,但找不到与实际问题相关的太多信息。

How do I get a consolidated list of zombie processes and daemon processes? How do I do it on different operating systems. Linux? AIX? Windows?

如何获得僵尸进程和守护进程的综合列表?我如何在不同的操作系统上做到这一点。Linux?艾克斯?视窗?

I am sure that, based on PID, we cannot identify the type of process. Running through a terminal might not help either.

我确信,基于 PID,我们无法识别进程的类型。通过终端运行也可能无济于事。

回答by kris123456

To get the list of Zombie and daemon process just write a psudo character dev driver, where you should navigate trough the task_struct and look for state

要获取僵尸和守护进程的列表,只需编写一个伪字符开发驱动程序,您应该在其中导航通过 task_struct 并查找状态

回答by kaiwan

With GNU ps on Linux:

在 Linux 上使用 GNU ps:

[

[

$ ps --version

procps-ng version 3.3.3

]

]

Zombies:

僵尸:

ps -lA | grep '^. Z'

will get you all zombies (note that the param is lowercase 'L', i.e., 'l' followed by 'A').

会给你所有的僵尸(注意参数是小写的“L”,即“l”后跟“A”)。

Daemons:

守护进程:

As @Barmar said there's no way to get daemons for certain, but a clue that a process is a daemon is that it's not associated with any TTY device. The 12th column of 'ps -Al' output is TTY; the 4th is PID, 14th is the process name. Hence:

正如@Barmar 所说,无法确定获得守护进程,但是进程是守护进程的一个线索是它不与任何 TTY 设备相关联。'ps -Al' 输出的第 12 列是 TTY;第 4 个是 PID,第 14 个是进程名称。因此:

ps -lA | awk ' == "?" {print , }'

will get you processes that are possiblydaemons; not guaranteed! :)

将为您提供可能是守护进程的进程;不保证!:)

回答by Ann B

Daemons are started by the init process, which means they have a PPID of 1.

守护进程由 init 进程启动,这意味着它们的 PPID 为 1。

Therefore:

所以:

ps -ef | awk ' == 1'

回答by madala

Try out this.

试试这个。

ps axo pid,ppid,pgrp,tty,tpgid,sess,comm |awk '==1' |awk '=='

In the above command I used the very properties of a daemon to filter them out, from all of existing processes in Linux.

在上面的命令中,我使用了守护进程的特性将它们从 Linux 中的所有现有进程中过滤掉。

The parent of a daemon is always Init, so check for ppid 1. The daemon is normally not associated with any terminal, hence we have ‘?' under tty. The process-id and process-group-id of a daemon are normally same The session-id of a daemon is same as it process id.

守护进程的父进程总是 Init,所以检查 ppid 1。守护进程通常不与任何终端关联,因此我们有“?” 在 tty 下。守护进程的 process-id 和 process-group-id 通常相同 守护进程的 session-id 与其进程 id 相同。

回答by Massimo

I wrote for daemons and the "old" sysv initd, you have to check if it is working on your distro.

我为守护进程和“旧的”sysv initd 编写了代码,您必须检查它是否在您的发行版上运行。

Good demons have well written startup scripts in /etc/initd

好恶魔在 /etc/initd 中写好了启动脚本

When changing runlevel, how does init know the running daemons ?

更改运行级别时,init 如何知道正在运行的守护进程?

It looks for their names in the directory

它在目录中查找他们的名字

/var/lock/subsys

So you can

这样你就可以

  • get the names list from there

  • scan all the running processes and check if the name is inside the list: bingo !

  • 从那里获取姓名列表

  • 扫描所有正在运行的进程并检查名称是否在列表中:宾果游戏!

To scan all the processes: list every subdirectory in

扫描所有进程:列出每个子目录

/proc

If its name is digits, it is the pid of a running process.

如果它的名称是数字,则它是正在运行的进程的 pid。

For example, the status of the process with pid 1234 is this file

比如pid为1234的进程状态就是这个文件

/proc/1234/status

Open it and get the first line, starts with "Name:"

打开它并获得第一行,以“名称:”开头

See