1 /* vi: set sw=4 ts=4: */
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
7 * Licensed under the GPL v2, 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)
35 if (strncmp(p->short_cmd, pidName, COMM_LEN-1) == 0) {
36 pidList=xrealloc( pidList, sizeof(long) * (i+2));
41 pidList[i] = i==0 ? -1 : 0;
45 long *pidlist_reverse(long *pidList)
48 while (pidList[i] > 0 && ++i);
52 for (j = 0; i > j; i--, j++) {
54 pidList[i] = pidList[j];