Added -z command line paramter to pidof which tells pidof to

try to find processes in uninterruptable (D) or zombie (Z) states.
This can cause pidof to hang, but produces a more complete process
list.
This commit is contained in:
Jesse Smith 2019-07-04 22:00:47 -03:00
parent 5f96543c96
commit 39df2f0fa3
3 changed files with 34 additions and 4 deletions

View File

@ -1,3 +1,13 @@
sysvinit (2.96) released; urgency=low
[ Jesse Smith ]
* Added -z command line paramter to pidof which tells pidof to
try to find processes in uninterruptable (D) or zombie (Z) states.
This can cause pidof to hang, but produces a more complete process
list.
sysvinit (2.95) released; urgency=low
[ Jesse Smith ]

View File

@ -24,6 +24,7 @@ pidof -- find the process ID of a running program.
.RB [ \-c ]
.RB [ \-n ]
.RB [ \-x ]
.RB [ \-z ]
.RB [ \-o
.IR omitpid[,omitpid...] ]
.RB [ \-o
@ -64,6 +65,10 @@ a status of true or false to indicate whether a matching PID was found.
.IP \-x
Scripts too - this causes the program to also return process id's of
shells running the named scripts.
.IP \-z
Try to detect processes which are stuck in uninterruptible (D) or zombie (Z)
status. Usually these processes are skipped as trying to deal with them can cause
pidof to hang.
.IP "-d \fIsep\fP"
Tells \fIpidof\fP to use \fIsep\fP as an output separator if more than one PID
is shown. The default separator is a space.
@ -92,6 +97,8 @@ so symbolic links to executables will also match.
.PP
Zombie processes or processes in disk sleep (states Z and D, respectively)
are ignored, as attempts to access the stats of these will sometimes fail.
The \-z flag (see above) tells pidof to try to detect these sleeping and zombie
processes, at the risk of failing or hanging.
.SH SEE ALSO
.BR shutdown (8),

View File

@ -135,9 +135,17 @@ NFS *nlist;
/* Did we stop all processes ? */
int sent_sigstop;
int scripts_too = 0;
/* Should pidof try to list processes in I/O wait (D) and zombie (Z) states? */
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#endif
int list_dz_processes = FALSE;
char *progname; /* the name of the running program */
#ifdef __GNUC__
__attribute__ ((format (printf, 2, 3)))
@ -598,8 +606,9 @@ int readproc(int do_stat)
if (startcode == 0 && endcode == 0)
p->kernel = 1;
fclose(fp);
if ( (strchr(process_status, 'D') != NULL) ||
(strchr(process_status, 'Z') != NULL) ){
if ( (! list_dz_processes) &&
( (strchr(process_status, 'D') != NULL) ||
(strchr(process_status, 'Z') != NULL) ) ){
/* Ignore zombie processes or processes in
disk sleep, as attempts
to access the stats of these will
@ -955,6 +964,7 @@ void pidof_usage(void)
printf(" -q Quiet mode. Do not display output\n");
printf(" -s Only return one PID\n");
printf(" -x Return PIDs of shells running scripts with a matching name\n");
printf(" -z List zombie and I/O waiting processes. May cause pidof to hang.\n");
printf("\n");
}
@ -1008,7 +1018,7 @@ int main_pidof(int argc, char **argv)
if ((token = getenv("PIDOF_NETFS")) && (strcmp(token,"no") != 0))
flags |= PIDOF_NETFS;
while ((opt = getopt(argc,argv,"qhco:d:sxn")) != EOF) switch (opt) {
while ((opt = getopt(argc,argv,"qhco:d:sxzn")) != EOF) switch (opt) {
case '?':
nsyslog(LOG_ERR,"invalid options on command line!\n");
closelog();
@ -1056,6 +1066,9 @@ int main_pidof(int argc, char **argv)
case 'x':
scripts_too++;
break;
case 'z':
list_dz_processes = TRUE;
break;
case 'n':
flags |= PIDOF_NETFS;
break;