Added patch from Walter Harms which allows pidof to run without
displaying output. In this mode pidof simply returns true or false without displaying PID values. Updated manual page with new -q (quiet) mode. Added -h flag for pidof, which was recognized before, but not used. The -h flag now displays brief usage information for pidof.
This commit is contained in:
parent
eda1f0d6ba
commit
f1ca96e1c1
@ -32,7 +32,7 @@ pidof -- find the process ID of a running program.
|
||||
.RB [ program.. ]
|
||||
.SH DESCRIPTION
|
||||
.B Pidof
|
||||
finds the process id's (pids) of the named programs. It prints those
|
||||
finds the process id's (PIDs) of the named programs. It prints those
|
||||
id's on the standard output. This program is on some systems used in
|
||||
run-level change scripts, especially when the system has a
|
||||
\fISystem-V\fP like \fIrc\fP structure. In that case these scripts are
|
||||
@ -44,7 +44,7 @@ a
|
||||
.IP \-s
|
||||
Single shot - this instructs the program to only return one \fIpid\fP.
|
||||
.IP \-c
|
||||
Only return process ids that are running with the same root directory.
|
||||
Only return process PIDs that are running with the same root directory.
|
||||
This option is ignored for non-root users, as they will be unable to check
|
||||
the current root directory of processes they do not own.
|
||||
.IP \-n
|
||||
@ -56,6 +56,9 @@ based file systems like
|
||||
Instead of using this option the the variable
|
||||
.B PIDOF_NETFS
|
||||
may be set and exported.
|
||||
.IP \-q
|
||||
Do not display matched PIDs to standard out. Simply exit with
|
||||
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.
|
||||
@ -76,7 +79,7 @@ the program behaves according to the name under which it is called.
|
||||
.PP
|
||||
When \fIpidof\fP is invoked with a full pathname to the program it
|
||||
should find the pid of, it is reasonably safe. Otherwise it is possible
|
||||
that it returns pids of running programs that happen to have the same name
|
||||
that it returns PIDs of running programs that happen to have the same name
|
||||
as the program you're after but are actually other programs. Note that
|
||||
that the executable name of running processes is calculated with
|
||||
.BR readlink (2),
|
||||
|
@ -919,6 +919,21 @@ void usage(void)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
void pidof_usage(void)
|
||||
{
|
||||
printf("pidof usage: [options] <program-name>\n\n");
|
||||
printf(" -c Return PIDs with the same root directory\n");
|
||||
printf(" -h Display this help text\n");
|
||||
printf(" -n Avoid using stat system function on network shares\n");
|
||||
printf(" -o <pid> Omit results with a given PID\n");
|
||||
printf(" -q Quiet mode. Do not display output\n");
|
||||
printf(" -s Only return one PID\n");
|
||||
printf(" -x Return PIDs of shells running scritps with a matchign name\n");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
/* write to syslog file if not open terminal */
|
||||
#ifdef __GNUC__
|
||||
__attribute__ ((format (printf, 2, 3)))
|
||||
@ -943,6 +958,7 @@ void nsyslog(int pri, char *fmt, ...)
|
||||
#define PIDOF_SINGLE 0x01
|
||||
#define PIDOF_OMIT 0x02
|
||||
#define PIDOF_NETFS 0x04
|
||||
#define PIDOF_QUIET 0x08
|
||||
|
||||
/*
|
||||
* Pidof functionality.
|
||||
@ -966,7 +982,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,"hco:sxn")) != EOF) switch (opt) {
|
||||
while ((opt = getopt(argc,argv,"qhco:sxn")) != EOF) switch (opt) {
|
||||
case '?':
|
||||
nsyslog(LOG_ERR,"invalid options on command line!\n");
|
||||
closelog();
|
||||
@ -974,6 +990,9 @@ int main_pidof(int argc, char **argv)
|
||||
case 'c':
|
||||
if (geteuid() == 0) chroot_check = 1;
|
||||
break;
|
||||
case 'h':
|
||||
pidof_usage();
|
||||
exit(0);
|
||||
case 'o':
|
||||
here = optarg;
|
||||
while ((token = strsep(&here, ",;:"))) {
|
||||
@ -999,6 +1018,9 @@ int main_pidof(int argc, char **argv)
|
||||
}
|
||||
flags |= PIDOF_OMIT;
|
||||
break;
|
||||
case 'q':
|
||||
flags |= PIDOF_QUIET;
|
||||
break;
|
||||
case 's':
|
||||
flags |= PIDOF_SINGLE;
|
||||
break;
|
||||
@ -1065,15 +1087,21 @@ int main_pidof(int argc, char **argv)
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ~flags & PIDOF_QUIET ) {
|
||||
if (!first)
|
||||
printf(" ");
|
||||
printf("%d", p->pid);
|
||||
}
|
||||
first = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!first)
|
||||
{
|
||||
if ( ~flags & PIDOF_QUIET )
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
clear_mnt();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user