]> granicus.if.org Git - procps-ng/commitdiff
pidof: show worker threads
authorJan Rybar <jrybar@redhat.com>
Tue, 7 Apr 2020 11:41:48 +0000 (13:41 +0200)
committerCraig Small <csmall@dropbear.xyz>
Fri, 10 Apr 2020 04:58:15 +0000 (14:58 +1000)
Reimplementation of pidof for procps toolset contains sort of deactivated code and does not return results for processes without task.cmdline entry (usually kernel worker threads). Old pidof and pgrep do that in comparison. Despite all perks provided by using pgrep instead, pidof should show those workers again.

pidof.c

diff --git a/pidof.c b/pidof.c
index cff91260a5d2ea5675fc8df74f0cc0193614a502..92456a0f63f23477cf81a9466c4594820ae66fdb 100644 (file)
--- a/pidof.c
+++ b/pidof.c
@@ -145,6 +145,7 @@ static void select_procs (void)
        static int size = 0;
        char *cmd_arg0, *cmd_arg0base;
        char *cmd_arg1, *cmd_arg1base;
+       char *stat_cmd;
        char *program_base;
        char *root_link;
        char *exe_link;
@@ -172,9 +173,9 @@ static void select_procs (void)
                        }
                }
 
-               if (!is_omitted(tid) && p_cmdline && *p_cmdline) {
+               if (!is_omitted(tid)) {
 
-                       cmd_arg0 = *p_cmdline;
+                       cmd_arg0 = (p_cmdline && *p_cmdline) ? *p_cmdline : "\0";
 
                        /* processes starting with '-' are login shells */
                        if (*cmd_arg0 == '-') {
@@ -196,12 +197,14 @@ static void select_procs (void)
                            !strcmp(program_base, cmd_arg0) ||
                            !strcmp(program, cmd_arg0) ||
 
+                           !strcmp(program, stat_cmd) ||
+
                            !strcmp(program, exe_link_base) ||
                            !strcmp(program, exe_link))
                        {
                                match = 1;
 
-                       } else if (opt_scripts_too && *(p_cmdline+1)) {
+                       } else if (opt_scripts_too && p_cmdline && *(p_cmdline+1)) {
 
                                cmd_arg1 = *(p_cmdline+1);