diff options
-rw-r--r-- | doc/getpid.html | 4 | ||||
-rw-r--r-- | src/execline/getpid.c | 7 |
2 files changed, 8 insertions, 3 deletions
diff --git a/doc/getpid.html b/doc/getpid.html index ef1410c..da4df66 100644 --- a/doc/getpid.html +++ b/doc/getpid.html @@ -26,7 +26,7 @@ then executes a program. <h2> Interface </h2> <pre> - getpid [ -E | -e ] <em>var</em> <em>prog...</em> + getpid [ -E | -e ] [ -P | -p ] <em>var</em> <em>prog...</em> </pre> <p> @@ -42,6 +42,8 @@ execs into <em>prog</em> with its arguments. <em>prog...</em>, exec into <tt>importas -ui <em>var</em> <em>var</em> <em>prog...</em></tt>. This substitutes <em>var</em> into the command line instead of putting it into the environment. </li> + <li> <tt>-p</tt> : get the pid of the current process. This is the default. </li> + <li> <tt>-P</tt> : use <tt>getpid</tt>'s <em>parent</em> pid instead. </li> </ul> <h2> Notes </h2> diff --git a/src/execline/getpid.c b/src/execline/getpid.c index 9bd7de5..058fe1b 100644 --- a/src/execline/getpid.c +++ b/src/execline/getpid.c @@ -9,12 +9,13 @@ #include <execline/execline.h> -#define USAGE "getpid [ -E | -e ] variable prog..." +#define USAGE "getpid [ -E | -e ] [ -P | -p ] variable prog..." #define dieusage() strerr_dieusage(100, USAGE) int main (int argc, char const *const *argv) { int doimport = 0 ; + int doppid = 0 ; char fmt[PID_FMT] ; PROG = "getpid" ; { @@ -27,6 +28,8 @@ int main (int argc, char const *const *argv) { case 'E' : doimport = 1 ; break ; case 'e' : doimport = 0 ; break ; + case 'P' : doppid = 1 ; break ; + case 'p' : doppid = 0 ; break ; default : dieusage() ; } } @@ -35,6 +38,6 @@ int main (int argc, char const *const *argv) if (argc < 2) dieusage() ; if (!argv[0][0] || strchr(argv[0], '=')) strerr_dief1x(100, "invalid variable name") ; - fmt[pid_fmt(fmt, getpid())] = 0 ; + fmt[pid_fmt(fmt, doppid ? getppid() : getpid())] = 0 ; el_modif_and_exec(argv + 1, argv[0], fmt, doimport) ; } |