1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
14 * Modified by Vladimir Oleynik for use with libbb/procps.c
15 * This finds the pid of the specified process.
16 * Currently, it's implemented by rummaging through
17 * the proc filesystem.
19 * Returns a list of all matching PIDs
20 * It is the caller's duty to free the returned pidlist.
22 pid_t* find_pid_by_name(const char* procName)
26 procps_status_t* p = NULL;
28 pidList = xmalloc(sizeof(*pidList));
29 while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_COMM))) {
30 if (strncmp(p->comm, procName, sizeof(p->comm)-1) == 0) {
31 pidList = xrealloc(pidList, sizeof(*pidList) * (i+2));
32 pidList[i++] = p->pid;
40 pid_t *pidlist_reverse(pid_t *pidList)
48 for (j = 0; i > j; i--, j++) {
50 pidList[i] = pidList[j];