Skip to content

Instantly share code, notes, and snippets.

@hochan222
Last active October 26, 2020 12:29
Show Gist options
  • Save hochan222/9ec4c2ae8933c317897174f7529154ad to your computer and use it in GitHub Desktop.
Save hochan222/9ec4c2ae8933c317897174f7529154ad to your computer and use it in GitHub Desktop.
mac bash shell timeout
(echo 'hello world') & sleep 1; kill $! 2> /dev/null || :
@hochan222
Copy link
Author

  • (echo 'hello world')
    Command to execute

  • & sleep 1;
    Maximum time to wait

  • kill $!
    Kill the most recently run process in the background

$! == 가장 최근에 실행 된 백그라운드 파이프 라인의 프로세스 Id

  • 2> /dev/null
    ignores errors thrown by kill

  • || :
    ignores the "fail" exit code when your code executes in less than the set number of seconds.

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