pidof/killall: allow find_pid_by_name to find running

processes started as scripts_with_name_longer_than_15_bytes.sh
 closes bug 4054 (and is generally neat)
This commit is contained in:
Denis Vlasenko
2008-07-17 18:39:36 +00:00
parent 18875bf772
commit 3b3ca113ed
5 changed files with 53 additions and 23 deletions

View File

@@ -111,8 +111,15 @@ int pgrep_main(int argc UNUSED_PARAM, char **argv)
if (proc->pid == pid)
continue;
cmd = proc->argv0;
if (!cmd)
if (!cmd) {
cmd = proc->comm;
} else {
int i = proc->argv_len;
while (i) {
if (!cmd[i]) cmd[i] = ' ';
i--;
}
}
/* NB: OPT_INVERT is always 0 or 1 */
if ((regexec(&re_buffer, cmd, 1, re_match, 0) == 0 /* match found */
&& (!OPT_ANCHOR || (re_match[0].rm_so == 0 && re_match[0].rm_eo == (regoff_t)strlen(cmd)))) ^ OPT_INVERT