Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    how to kill the process after specific time?


    Hi All,

    I need to define the specific duration to run a process. i mean after specific time the process should be killed autometically.

    plese help me to do this.

    Thanks.

  2. #2
    Run ur process
    ps -e | grep "<process name>" | awk '{print $3}' ---This will give time
    compare with ur required time and kill

  3. #3
    Thanks for your reply.
    but again I will have to kill the process manually with this command if i am understanding this properly.

    how will i run this command when i ll run the process? I mean if i run a process, at the same time can i define its duration? or after 5 hours this process automatically killed?

  4. $spacer_open
    $spacer_close
  5. #4
    Thanks ....

    I have done this ....

    see the example ... just wrote a small script


    runtime=${1:-1m}
    mypid=$$
    cp /Database/Client_db_200802110231.BAK .&
    cpid=$!
    sleep $runtime
    kill -s SIGTERM $cpid
    echo "Both processes are terminated".

    I mean now i can define the running time duration of all processes like cp with the time.

    Cheers.

  6. #5
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    Quote Originally Posted by samengr
    I need to define the specific duration to run a process. i mean after specific time the process should be killed autometically.
    You can kill a process using ulimit by specifying the resources it will have available. The -t option will allow you to specify the max cpu seconds any process run from your shell can use (after which time the process will be killed).

    I don't know of a clever way to kill a process after a certain amount of clock time passes. The best thing I can think of at the moment is a simple at job to run the kill command at the time you specify.

    edit: Just noticed your kludge using sleep; glad you worked it out.

Posting Permissions

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