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.
18 * Modified by Vladimir Oleynik for use with libbb/procps.c
19 * This finds the pid of the specified process.
20 * Currently, it's implemented by rummaging through
21 * the proc filesystem.
23 * Returns a list of all matching PIDs
24 * It is the caller's duty to free the returned pidlist.
26 long* find_pid_by_name(const char* pidName)
32 pidList = xmalloc(sizeof(long));
33 while ((p = procps_scan(0)) != 0) {
34 if (strncmp(p->short_cmd, pidName, COMM_LEN-1) == 0) {
35 pidList = xrealloc( pidList, sizeof(long) * (i+2));
36 pidList[i++] = p->pid;
40 pidList[i] = i==0 ? -1 : 0;
44 long *pidlist_reverse(long *pidList)
47 while (pidList[i] > 0 && ++i);
51 for (j = 0; i > j; i--, j++) {
53 pidList[i] = pidList[j];