]> granicus.if.org Git - procps-ng/commitdiff
pidof: support for omitted %PPID and additional separators
authorJaromir Capik <jcapik@redhat.com>
Mon, 14 Oct 2013 13:38:33 +0000 (15:38 +0200)
committerJaromir Capik <jcapik@redhat.com>
Mon, 14 Oct 2013 13:38:33 +0000 (15:38 +0200)
This commit introduces support for special %PPID value that
can be passed to the -o option as a substitution for parent
PID. It also allows users to use two additional separators
for omitted PIDs - colon and semicolon.

pidof.1
pidof.c

diff --git a/pidof.1 b/pidof.1
index f2544c8b5f75b5cb70e72d9350acff244e4f8008..f49cd2340f95018f7465fbda4c124b99fabd33fe 100644 (file)
--- a/pidof.1
+++ b/pidof.1
@@ -44,7 +44,9 @@ the current root directory of processes they do not own.
 Scripts too - this causes the program to also return process id's of
 shells running the named scripts.
 .IP "-o \fIomitpid\fP"
-Tells \fIpidof\fP to omit processes with that process id.
+Tells \fIpidof\fP to omit processes with that process id. The special
+pid \fB%PPID\fP can be used to name the parent process of the \fIpidof\fP
+program, in other words the calling shell or shell script.
 .SH "EXIT STATUS"
 .TP
 .B 0
diff --git a/pidof.c b/pidof.c
index a39a4c0cfe58ed3599d38278377b6bfd6ae40487..72344e760daf2bb32957dec9bed92c5fe8ea8eea 100644 (file)
--- a/pidof.c
+++ b/pidof.c
@@ -246,10 +246,15 @@ static void add_to_omit_list (char *input_arg)
        pid_t omit_pid;
 
        omit_str = NULL;
-       omit_str = strtok(input_arg, ",");
+       omit_str = strtok(input_arg, ",;:");
        while (omit_str) {
 
-               omit_pid = strtoul(omit_str, &endptr, 10);
+               if (!strcmp(omit_str,"%PPID")) {  /* keeping this %PPID garbage for backward compatibility only */
+                       omit_pid = getppid();     /* ... as it can be replaced with $$ in common shells */
+                       endptr = omit_str + sizeof("%PPID") - 1;
+               } else {
+                       omit_pid = strtoul(omit_str, &endptr, 10);
+               }
 
                if (*endptr == '\0') {
                        if (omit_count == omit_size) {
@@ -265,7 +270,7 @@ static void add_to_omit_list (char *input_arg)
                        xwarnx(_("illegal omit pid value (%s)!\n"), omit_str);
                }
 
-               omit_str = strtok(NULL, ",");
+               omit_str = strtok(NULL, ",;:");
        }
 }