1

I'm fumbling my way through with this one, as a novice with all things linux so please be patient :)

I would like to output the process ID of a program to a file. From my readings this is generally achieved by a special pling variable which linux maintains:

make_something_run.sh &
echo $! > /var/run/someting.pid

however when I try to apply this in my startup script for red5, it creates the pid file successfully but no id is found within. This is the specific script:

start)
    echo -n "Starting Red5"
    echo -n " "
    cd $RED5_HOME
    su -s /bin/bash -c "$RED5_HOME/$RED5_PROG.sh &" $RED5_USER
    echo "$RED5_HOME/$RED5_PROG.sh &"
## su -s /bin/bash -c "$RED5_HOME/$RED5_PROG.sh > start.log &" $RED5_USER
    echo $! > /var/run/red5.pid
    wait $!
    sleep 2
   ;;

I've tried with and without the wait $! (which I believe waits for the process to start before writing the file?) with no success. My only other thoughts are to do something fancy with grep and ps aux to extract the number, though I've no idea if that would be a reliable approach.

milks
  • 113

1 Answers1

2

You need to add an echo
make_something_run.sh & echo $! > /var/run/someting.pid
                                                     ^

http://www.odi.ch/weblog/posting.php?posting=291

EDIT:
su -s /bin/bash -c "${RED5_HOME}/${RED5_PROG}.sh & echo \$! > /var/run/red5.pid" $RED5_USER

or
https://stackoverflow.com/questions/6197165/getting-a-pid-from-a-background-process-run-as-another-user

Diblo Dk
  • 738