From 3b3ca113ed00a6781a28172bb3a6860a5f79ea02 Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Thu, 17 Jul 2008 18:39:36 +0000 Subject: 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) --- procps/pgrep.c | 9 ++++++++- procps/pidof.c | 4 +--- 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'procps') diff --git a/procps/pgrep.c b/procps/pgrep.c index 7b3cd8e50..0e8e5294e 100644 --- a/procps/pgrep.c +++ b/procps/pgrep.c @@ -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 diff --git a/procps/pidof.c b/procps/pidof.c index 2519473e8..780504433 100644 --- a/procps/pidof.c +++ b/procps/pidof.c @@ -22,7 +22,6 @@ int pidof_main(int argc UNUSED_PARAM, char **argv) unsigned first = 1; unsigned opt; #if ENABLE_FEATURE_PIDOF_OMIT - char ppid_str[sizeof(int)*3 + 1]; llist_t *omits = NULL; /* list of pids to omit */ opt_complementary = "o::"; #endif @@ -39,8 +38,7 @@ int pidof_main(int argc UNUSED_PARAM, char **argv) while (omits_p) { /* are we asked to exclude the parent's process ID? */ if (strcmp(omits_p->data, "%PPID") == 0) { - sprintf(ppid_str, "%u", (unsigned)getppid()); - omits_p->data = ppid_str; + omits_p->data = utoa((unsigned)getppid()); } omits_p = omits_p->link; } -- cgit v1.2.3