On Mon, Oct 23, 2006 at 10:23 PM, David Korn <[email protected]> wrote: > cc: [email protected] > Subject: Re: [ast-users] Trouble with getting the child process pid ("$!") in > ksh93 ... > -------- > >> While working on another project I hit a problem with obtaining the >> process ID of the current child process (I'd like to "renice" it to a >> lower priority (however in a different way than the "bgnice" option >> does)). >> >> Example: >> -- snip -- >> $ (ksh93 -c 'px() { echo "p1=${$} p2=${!}" ; } ; px ; ( px ) &') >> p1=27961 p2= >> p1=27961 p2= >> -- snip -- >> The output of $$ is expected... but how can I get the process ID of the >> current child process ? >> >> For comparisation "bash" returns the current background process ID in $! >> _within_ the child: >> -- snip -- >> $ (bash -c 'px() { echo "p1=${$} p2=${!}" ; } ; px ; ( px ) &') >> p1=27964 p2= >> p1=27964 p2=27965 >> -- snip -- >> >> I am not sure whether this behaviour is POSIX conformant... but it is >> IMO usefull... >> >> ... any ideas/suggestions/rants/etc. welcome... > > The way $! is defined is that it is the pid of the last background > process or coprocess. When a subshell starts, there is no > most recent background job so there is not pid. > > However, the standard isn't clear as to what the value of $! is > when there was no background jobs executed. Perhaps initializing > it to the current pid makes sense. > > I will post this onto the austin group list and see whether > anyone thinks that it would violate the standard.
ping! ... has there been any feedback yet ? I just stumbled over the issue (again) while trying to craft a realtime signal test which nests child processes like a "Matryoshka doll" (e.g. see http://en.wikipedia.org/wiki/Matryoshka_doll) ... ... the issue I ran into is that $$ always refers to the base shell process and AFAIK there no easy way to pass the pid of the current shell child process to it's child processes... ---- Bye, Roland -- __ . . __ (o.\ \/ /.o) [email protected] \__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer /O /==\ O\ TEL +49 641 3992797 (;O/ \/ \O;) _______________________________________________ ast-users mailing list [email protected] http://lists.research.att.com/mailman/listinfo/ast-users
