edeca.net logo
  • rss
  • Home
  • Graphics
  • Electronics
  • Computing
    • ROT Util
    • MOTD maker
    • GNU screen config
    • VB6 reverse DNS
    • VB6 RichTextBox control
  • About

Limiting command runtime in Linux

David | May 2, 2010

It is sometimes useful to limit the running time of a process, either to stop it from using up all resources or to make sure nightly cron jobs don’t continue into working hours.

I needed this for rsync, to let a remote backup server slowly catch up if large amounts of data were added to the live server during the day. A useful post on the rsync mailing list discusses an rsync patch but also the timeout command.

After installing (the Debian package is simply timeout) it is as easy as running with the number of seconds to run for:

$ timeout 21600 rsync -a ...

It is also possible to specify the signal which will be sent to a program, which is useful if you do not want to simply send SIGKILL. I used SIGHUP in the hope that rsync would have a chance to exit gracefully:

$ timeout -1 21600 rsync -a ...

A full list of signals and their numeric values can be found in man 1 kill.

A wrapper script is also available from Johannes Buchner.

Categories
Computing
Tags
linux, rsync
Comments rss
Comments rss
Trackback
Trackback

« Using the hardware USART with BoostC and a PIC I am not a photographer »

One Response to “Limiting command runtime in Linux”

  1. Evil Dave says:
    June 15, 2010 at 8:10 pm

    Or more portably, ‘ulimit’, which should be available on all Unix-a-likes. It may be a shell built-on on some systems.

Leave a Reply

Click here to cancel reply.

Categories

  • Computing
  • Electronics
  • General
  • Perl
  • Photography

Archives

  • July 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • November 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009

Links

  • My photo gallery
  • Pookey's site

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox