Skip to content

Instantly share code, notes, and snippets.

@todgru
Created January 22, 2013 01:54
Show Gist options
  • Save todgru/4591379 to your computer and use it in GitHub Desktop.
Save todgru/4591379 to your computer and use it in GitHub Desktop.
bash, BASH, sleep, at, kill

#BASH

BASH Process Control

response=$(curl --write-out %{http_code} --silent --output /dev/null servername)
  • Start <command>, assign the pid value to $PID, sleep for N minutes. Then end process $PID:

    <command> & PID=$!
    sleep ${N}m
    kill -HUP $PID
    

Something funky about that methed. My tests failed.

  • Asychronous version:

    n=5
    some_command &
    pid=$!
    at now + $n minutes <<<"kill -HUP $pid"
    

According to SO "The benefit of using at over waiting for sleep is that your script wont block waiting for the sleep to expire. You can go and do other things and at will asynchronously fire at the specified time. Depending on your script that may be a very important feature to have."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment