Hi,

I'm using a bash scripts that is running one of the functions in the scripts as 
a "background".

function my_func {
    MAINPID=$$      # Does not work, report PID of main process.
    MYPID=$!           # Work with bash 3.0, return "unbound" value for bash 4.0
    echo "Deamon run as PID=$MYPID MAIN=$MAINPID"
     ...
}

# Main
(my_func) &

With BASH 3.0, the backgrounded task could access the PID of the parent using 
"$$", and the PID
Of itself as "$!".

With BASH 4.0, the script fail, the "$!" is not available to the child process.

Is it possible to add back the functionality to allow the child process to 
somehow retrieve it's OWN PID.
I assume that the behavior of  "$$" cannot be modified at this time.

Is there any other workaround ?

Thanks
Yair Lenga

Reply via email to