REQ: [icecast-dev] Parent Id
gtgbr at gmx.net
gtgbr at gmx.net
Mon Dec 1 14:34:21 PST 2003
Dave St John wrote:
> Before the official release of icecast2 1.0 (non beta) i would like to see
> pid file management,
> ive discussed this before on how to capture the pid, but ended up with alot
> of bash rigamaroo that mounted to even more
> headaches.
If I understand you correctly, all you want is the PID of the Icecast
process and not of its children (probably to be able to script, send
signals to the right process, etc.)
Well, I'm using OpenBSD mostly, and there's no "pidof" or "killall" here
... if I need to script something, I use the following which can be
considered ``safe''. (The function is what's doing the job, the rest is
just how I use it stand-alone sometimes). Simple, but effective - no
insane greppery, no conflicts with additional `ps` output, nor pidof
having any problems with itself (it can never have a PPID of 1, so it
won't return its own PID, ever).
--- snip ---
#!/bin/sh
# pidof() code by Christoph Moench-Tegeder
# and Michael Erdely (from tech at openbsd.org)
#
_pidof()
{
ps -acxo pid,ppid,command | \
awk "\$3==\"$1\" && \$2==\"1\" {print \$1}"
}
if [ $# -ne 1 ] ; then
cat << _EOF
Usage: $0 <daemon_name>
$0 displays the PID of a process,
if its parent PID is 1.
$0 exits with the return code 0
if there is a PID to report,
otherwise the return code is 1.
_EOF
exit 0
fi
_PID="`_pidof $1`"
test ${_PID} && echo "${_PID}" || exit 1
exit 0
--- snap ---
In order for _pidof() to work with Icecast2, you have to let it become a
daemon using the -b parameter, e.g. "icecast -b -c icecast.xml"
PID files are quite useless junk on the harddisk in most cases... IMO
they make only sense if you have to run a program in the foreground and
send signals like SIGUSR1 to it (those that don't have hotkeys like
CTRL+C). Besides, they come with their own set of potential problems.
Anyways - Icecast2 is very likely to get optional PID file support some
time, but here's already a neat solution today. :)
<p>Moritz
--- >8 ----
List archives: http://www.xiph.org/archives/
icecast project homepage: http://www.icecast.org/
To unsubscribe from this list, send a message to 'icecast-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the Icecast-dev
mailing list