> I need to write a shell that can return the name if it's parent
> process. In other words, I have a process named parent_sh. parent_sh calls
> a script child_sh. I want child_sh to be able to print to the screen "I
> was called by parent_sh".
in more detail, perhaps someone will be able to suggest a technique that
avoids this requirement.
I don't know what you mean by this last bit (from `but' onwards); it seemsQuote:> My initial thought was to go with ps and an awk script, but ps deals more
> with the command running from the script, rather than the script name.
to me that your idea of using ps is a pretty good one. ps is (essentially)
the only way to translate a process id into a process name in a shell script
-- and it's certainly the most portable, though the code typically needs to
be tweaked to work on some systems.
POSIX sh and ksh provide the $PPID variable which contains the process id of
the parent process; you can parse the output of ps (carefully -- the number
may crop up elsewhere in the output) to find the line with that pid and the
name of the process it corresponds to. One other thing: be aware that the
parent might have died by the time you run ps.
** Please send on-topic followups by Usenet, not email **