You're replying to a comment by Coder.C.

Coder.C Permalink
August 28, 2012, 17:28

This is how to write alarm in bash:

function alarm() {
    timeout=$1; shift;
    bash -c "$@" &
      sleep $timeout
      kill $pid 2> /dev/null
    } &
    wait $pid 2> /dev/null
    return $?

alarm 1 "echo >/dev/tcp/" && echo "Y" || echo "N"

//this prints 'N' in ~1s

alarm 60 "echo >/dev/tcp/" && echo "Y" || echo "N"

//this still returns almost immediately and prints "Y"

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "browser_333": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.