Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Subshells and parameters



In the last episode (May 13), Vincent Lefevre said:
> On 2006-05-12 08:09:26 -0400, Lloyd Zusman wrote:
> > So how can we get the process ID of any given subshell?
> 
> dixsept:~> cat > getpid.c
> #include <stdio.h>
> #include <unistd.h>
> int main(void)
> {
>   printf("%d\n", (int) getppid());
>   return 0;
> }
> dixsept:~> gcc -Wall -O2 getpid.c -o getpid
> dixsept:~> echo $$; ./getpid
> 13372
> 13372
> dixsept:~> (echo $$; ./getpid)
> 13372
> 14153
> dixsept:~> (stat +link /proc/self; ./getpid)
> 14168
> 14168
> 
> Note: as Peter said, /proc is specific to Linux.

You could even use zsh itself for this:

function getppid() { $SHELL -fc 'echo $PPID' }

-- 
	Dan Nelson
	dnelson@xxxxxxxxxxxxxxx



Messages sorted by: Reverse Date, Date, Thread, Author