Unix Shell - Re: what alternatives does a shell command have in determining its parent?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > May 2007 > Re: what alternatives does a shell command have in determining its parent?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: what alternatives does a shell command have in determining its parent?
Andrew Smallshaw

2007-05-25, 1:19 pm

On 2007-05-24, Stephane CHAZELAS <this.address@is.invalid> wrote:
>
> Note that it is not clear what $PPID contains, at least
> according to POSIX. It says:
>
> PPID
> Set by the shell to the decimal process ID of the
> process that invoked this shell. In a subshell (see
> Shell Execution Environment), PPID shall be set to the
> same value as that of the parent of the current shell.
> For example, echo $ PPID and ( echo $ PPID ) would
> produce the same value. This volume of IEEE Std
> 1003.1-2001 specifies the effects of the variable only
> for systems supporting the User Portability Utilities
> option.
>
> That doesn't make sense to me. How would a process invoke
> another process? The most sensible way would be via an exec*()
> system call, in which case $$ would be the same as $PPID.


Well, I'll begin by putting this awkward use of the word 'invoke'
to one side for a moment and considering the matter from first
principles.

Under Unix or indeed POSIX, processes are _not_ created by exec().
That job is done by fork(). The exec...() functions (usually
execve() under the hood although I doubt POSIX mandates this)
_modify_ an _existing_ process. Replacing the entire process image
is an extensive modification but it is a modification nevertheless.
Therefore if we talk of a process creating a process we can only
be referring to fork() and not exec...().

> The definition for "invoke" is not very helpful:
>
> To perform command search and execution actions, except
> that searching for shell functions and special built-in
> utilities is suppressed; see also Execute.


.... and the definition of Execute is not more enlightening.
Indeed, it is written in pretty much the same terms.

However, if we go back to our first principles, if we talk about
a process invoking _another_ process, we _must_ be talking about
fork(). If you read between the lines in the invoke definition,
it appears to be talking about the whole sequence of tasks in
spawning a child process, beginning with locating the executable
and fianlly exec'ing it. The fork in the middle is not mentioned.
Presumably it is implied but I'd agree clarification would be
helpful. Regardless, the intent seems pretty clear to me.

--
Andrew Smallshaw
andrews@sdf.lonestar.org
[who has just found a bug in fmt with paragraphs that start with a '.'...]
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com