![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can a child process return a specific value to a parent process ? | Ametis1970 | High Level Programming | 8 | 04-10-2008 12:22 AM |
| about child process | compbug | UNIX for Dummies Questions & Answers | 12 | 03-22-2006 07:55 PM |
| gdb to child process | shriashishpatil | UNIX for Advanced & Expert Users | 4 | 12-12-2005 07:57 AM |
| KDM child process | larryase | UNIX for Dummies Questions & Answers | 6 | 01-24-2005 05:41 PM |
| Child Process PID | skannan | High Level Programming | 2 | 06-10-2002 08:54 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
This is not the same as a few of the other posted items dealing with sub-process pids (that I saw anyway).
If zot contains: echo "main mypid: $$ - lastpid: $!"Then: ksh zot (under Solaris and MKS) results in: main mypid: 7318 - lastpid:It surprises me that in the forked child process, that $$ still returns the pid of the main process. i.e. both show $$ as 7318 - I would have expected the child to have $$ be $7320. (You can ignore the ppid - I was looking at related notions.) If you do: "grep 7320 xxx" you get: root 7320 7318 0 13:59:45 pts/9 0:00 ksh zotwhich clearly shows the child process and if you were to "kill -9" that pid before the 5 seconds runs out, you would not get the second block line. My intention was for the child process to record its own pid rather than the parent doing it on its behalf. I realise that the parent can use $! but why can the child not use $$ for its own PID? By the way, if you extract the block of code and put it in a separate file and call it, then you get the expected results. Thank you in advance for any insights. Michel |
|
||||
|
Then how would the following ever work:
xxx=$(date)if $xxx were coerced when the (...)& is being scanned, then the two echo statements would always show the same time but they don't (you can try it). Are you suggesting that $$ is coerced by different rules than $xxx? |
|
||||
|
Thanks for the insights.
I do find the behaviour borderline nuts presuming different rules for coercing variables. An arguably valid definition I can think of as an alternate is that "$$" is by definition the initial shell's PID as opposed to the current process's PID, independent of sub-shells much like PPID is the parent of the initial shell regardless of being in a sub-shell or not. This is consistent with a few ksh man pages I dug up though not obvious. It also seems to be consistent with a few experiments I tried with "eval" with a composite string that results in "$$" which would preclude the initial parsing of the (....)& from coercing a manifest $$ and that also produced the same result. That ksh treats a subshell differently from a forked instance of ksh is consistent with other aspects of behaviour (e.g. variables need not be exported to be seen by a sub-shell) but it sure messes up the notion of using inline code vs external scripts in any consistent manner. I will derive an alternative strategy (messing with ps -ef is not an option because my code needs to run under Solaris and Windows/MKS wherein ps differs due to the information about process parameters maintained by Windows). Thanks again. Michel |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|