pid, and hence will complain about 'NONE' or 'MULTIPLE' as output by
'pid'. Correspondingly, adjust some comments in 'pid', including in
particular suggesting its use with 'after'.
git-svn-id: svn://svn.tartarus.org/sgt/utils@9719
cda61777-01e9-0310-a592-
d414129be87e
fprintf(stderr, "%s: parameter `%s' unexpected\n", pname, p);
return 1;
} else {
- pid = atoi(p);
+ char *end;
+ errno = 0;
+ pid = strtol(p, &end, 0);
+ if (errno == ERANGE || *end || pid < 0) {
+ fprintf(stderr, "%s: unable to parse `%s' as a pid\n",
+ pname, p);
+ return 1;
+ }
}
}
}
\cq{NONE} or \cq{MULTIPLE} if it finds no matching process or more
than one. This is a mode suitable for use as an argument to
\cw{strace} (which expects exactly one process ID after its \cw{-p}
-argument) or \cw{gdb} (which expects a single pid too); the \cq{NONE}
-or \cq{MULTIPLE} answers will provoke a command-line parsing error
-rather than trying to trace the wrong process or expanding to a less
-obviously wrong command line. Use the \cw{-a} option to instead make
-\cw{pid} output a full list of pids that match (e.g. if you want to
-pass them all to \cw{kill}(\e{1}).
+argument) or \cw{gdb} or \cw{after} (which expect a single pid as an
+argument); the \cq{NONE} or \cq{MULTIPLE} answers will provoke a
+command-line parsing error rather than trying to trace the wrong
+process or expanding to a less obviously wrong command line. Use the
+\cw{-a} option to instead make \cw{pid} output a full list of pids
+that match (e.g. if you want to pass them all to \cw{kill}(\e{1}).
You can also provide arguments to the command you're searching for, to
narrow your search further. For example, if you have several
*
* Same basic idea as Debian's "pidof", in that you type 'pid command'
* and it finds a process running that command and gives you the pid;
- * but souped up with various pragmatic features such as recognising
- * well known interpreters (so you can search for, say, 'pid
- * script.sh' as well as 'pid bash' and have it do what you meant).
+ * but differs in details, for example it will search for scripts by
+ * default rather than requiring pidof's -x option, and it will also
+ * look for command-line arguments ('pid make test') and try to find
+ * the parent process of a bunch of forks from the same shell script
+ * invocation.
*
* Currently tested only on Linux using /proc directly, but I've tried
* to set it up so that the logic of what processes to choose is