Parent process ID
James_Rogers
jim at hp-ptp.HP.COM
Sat Aug 12 04:28:16 AEST 1989
The previous function had some drawbacks (spawning a background job,
excess output, etc.).
A much more concise set of functions to do the same thing in ksh is:
function second {
echo "$2\c"
}
function ppid {
second `ps -fp $$ | cut -c15-20`
echo
}
These functions work cleanly in the ksh. You will not get the same results
in sh because functions in sh are run as separate processes.
In ksh functions are run as part of your existing shell.
For sh you would define the functions as follows:
second () {
echo "$2\c"
}
ppid () {
second `ps -fp $1 | cut -c15-20`
echo
}
You would then call ppid in the following manner:
ppid $$
This would pass your pid to "ppid" and then everything would execute properly.
Jim Rogers
More information about the Comp.unix.questions
mailing list