e0b30b
diff --git a/pidof.c b/pidof.c
e0b30b
index b0d08cc..90ecb13 100644
e0b30b
--- a/pidof.c
e0b30b
+++ b/pidof.c
e0b30b
@@ -142,6 +142,7 @@ static void select_procs (void)
e0b30b
 	static int size = 0;
e0b30b
 	char *cmd_arg0, *cmd_arg0base;
e0b30b
 	char *cmd_arg1, *cmd_arg1base;
e0b30b
+	char *stat_cmd;
e0b30b
 	char *program_base;
e0b30b
 	char *root_link;
e0b30b
 	char *exe_link;
e0b30b
@@ -167,9 +168,10 @@ static void select_procs (void)
e0b30b
 			}
e0b30b
 		}
e0b30b
 
e0b30b
-		if (!is_omitted(task.XXXID) && task.cmdline && *task.cmdline) {
e0b30b
+		if (!is_omitted(task.XXXID)) {
e0b30b
 
e0b30b
-			cmd_arg0 = *task.cmdline;
e0b30b
+			cmd_arg0 = (task.cmdline && *task.cmdline) ? *task.cmdline : "\0";
e0b30b
+			stat_cmd = task.cmd ? task.cmd : "\0";
e0b30b
 
e0b30b
 			/* processes starting with '-' are login shells */
e0b30b
 			if (*cmd_arg0 == '-') {
e0b30b
@@ -191,12 +193,14 @@ static void select_procs (void)
e0b30b
 			    !strcmp(program_base, cmd_arg0) ||
e0b30b
 			    !strcmp(program, cmd_arg0) ||
e0b30b
 
e0b30b
+			    !strcmp(program, stat_cmd) ||
e0b30b
+
e0b30b
 			    !strcmp(program, exe_link_base) ||
e0b30b
 			    !strcmp(program, exe_link))
e0b30b
 			{
e0b30b
 				match = 1;
e0b30b
 
e0b30b
-			} else if (opt_scripts_too && *(task.cmdline+1)) {
e0b30b
+			} else if (opt_scripts_too && task.cmdline && *(task.cmdline+1)) {
e0b30b
 
e0b30b
 				cmd_arg1 = *(task.cmdline+1);
e0b30b