Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to know the pid of a function that was run as child process on a script


echo "pid=$$;ppid=$PPID"
ps -p $$
function FUNCtstPsSelf() { 
    sleep 3;
    echo "$FUNCNAME:pid=$$;ppid=$PPID";
    ps -p $$ -o pid,ppid,command; 
sleep 1;

but it can't find the pid! what now?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Try $BASHPID instead of $$. One of the two occurrences of $$ in the man page is to explain when it differs from $BASHPID, including "subshells that do not require bash to be re-initialized", which may include your background function processes?

share|improve this answer
worked, here a simple example function FUNCtst() { echo "$$,$BASHPID"; };export -f FUNCtst;FUNCtst;FUNCtst&, thx! –  Aquarius Power Jun 9 '13 at 17:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.