Find the answer to your Linux question:
Results 1 to 7 of 7
Hi All, Hope someone can help. I am running memcached on a few servers, this runs OK. What I would like to do is create a runtime script, so I ...
  1. #1
    Just Joined! paulmroberts's Avatar
    Join Date
    Jun 2007
    Posts
    5

    Cool Find and kill process

    Hi All,

    Hope someone can help.

    I am running memcached on a few servers, this runs OK.

    What I would like to do is create a runtime script, so I can stop, start & restart the process any time if required and also so that it starts at boot time.

    Starting the process in a script is straight forward, but stopping it is a bit different since the process ID changes each time.

    So far I have been using a separate script to kill the process:

    #!/bin/bash

    if [$1 -eq ""]; then
    echo "Usage : ./pkill.sh <process name>"
    else
    get_proc=`ps -e -o pid,command | grep $1`
    echo $get_proc > get_it
    get_pid=`gawk -F" " '{ print $1 }' get_it`
    kill $get_pid
    fi


    but this requires me to run a script from within a script, I'm sure there is a better way...

    Regards
    Paul.

  2. #2
    Linux Newbie unchiujar's Avatar
    Join Date
    Oct 2006
    Posts
    194
    If the name stays the same you can try something like:

    Code:
    kill -15 $(pidof [name_of_process])

  3. #3
    Just Joined! paulmroberts's Avatar
    Join Date
    Jun 2007
    Posts
    5
    Ah, thanks, I'll give it a go and let you know

  4. #4
    Just Joined! paulmroberts's Avatar
    Join Date
    Jun 2007
    Posts
    5
    Hi,

    I just get the usage message back

    kill: usage: kill [-s sigspec | -n signum | -sigspec] [pid | job]... or kill -l [sigspec]

    Any ideas?

  5. #5
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Try:
    pkill name_pattern_here

    See the manpages for pgrep(1) for more details on using pkill.

  6. #6
    Linux User
    Join Date
    Feb 2006
    Posts
    484
    or maybe chose the easy way

    killall -9 <process_name>

  7. #7
    Just Joined! paulmroberts's Avatar
    Join Date
    Jun 2007
    Posts
    5
    pkill process_name did the trick.

    Thanks everyone.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •