Results 1 to 2 of 2
Hi to all,
my problem refers to $$ behaviour. If I have this script, in which I try to read bgFunc's PID from itself:
Code:
#!/bin/sh
bgFunc()
{
echo "bgFunc ...
- 10-24-2010 #1Just Joined!
- Join Date
- Oct 2010
- Posts
- 1
Background PID introspection
Hi to all,
my problem refers to $$ behaviour. If I have this script, in which I try to read bgFunc's PID from itself:
PID returned from $$ in bgFunc is equal to main's PID, and NOT to "spawned bgFunc PID".Code:#!/bin/sh bgFunc() { echo "bgFunc PID: $$" } #main bgFunc & echo "spawned bgFunc PID: $!" echo "main PID: $$"
How can I read bgFunc's PID from bgFunc itself?
- 10-25-2010 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
bigfunc() is a shell function, not a process, so $! will naturally return the shell's pid. IE, $! will equal $$.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote