Re: [LUNI] Kill running process in a script.....

From: Simon L. Epsteyn (seva@sevatech.com)
Date: Fri Mar 30 2001 - 16:59:30 CST

  • Next message: Martin Maney: "Re: [LUNI] Northpoint to auction off equipment in Chicago"

    On 30 Mar 2001, Casey Cichon wrote:

    > I have a question for you guys.....
    >
    > When I start pppd I have a small script that starts stuff like LICQ. When I bring the daemon down I can execute another script. I want to end some stuff in that script like this:
    >
    > kill ( - something) <looked up pid>
    >
    > can do the kill....
    > the only way I know how to look up pids is with ps, which I don't think will work for me in this situation.
    >
    > Any help would be appreciated.

    Casey,

    Try /sbin/pidof:

            NAME
                   pidof -- find the process ID of a running program.

            SYNOPSIS
                   pidof [-s] [-x] [-o omitpid] [-o omitpid..] program [program..]

    For example this is how it's done in /etc/init.d/function of Red Hat Linux
    7:

            # A function to find the pid of a program.
            pidofproc() {
                    base=`basename $1`

                    # Test syntax.
                    if [ $# = 0 ] ; then
                            echo "Usage: pidofproc {program}"
                            return 1
                    fi

                    # First try "/var/run/*.pid" files
                    if [ -f /var/run/${base}.pid ] ; then
                            pid=`cat /var/run/${base}.pid | { read foo ; echo $foo ; }`
                            if [ "$pid" != "" ] ; then
                                    echo $pid
                                    return 0
                            fi
                    fi

                    # Next try "pidof"
                    pid=`pidof -o $$ -o $PPID -o %PPID -x ${base}`
                    if [ "$pid" != "" ] ; then
                            echo $pid
                            return 0
                    fi
            }

    /Simon

    -=-
    Linux Users Of Northern Illinois: General Discussion Mailing list.
    For unsubscription, archives, and announcements only see http://luni.org



    This archive was generated by hypermail 2b29 : Fri Mar 30 2001 - 17:08:05 CST

  •