Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5966763
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:50:46+00:00 2026-05-22T19:50:46+00:00

How can I limit processes to less than 1s CPU time in Bash? I

  • 0

How can I limit processes to less than 1s CPU time in Bash? I am using version 4.1.5(1) and if I type ulimit -t 0.5 command, I get:

-bash: ulimit: 0.5: invalid number

I am using ulimit -t 1 command as an imperfect substitute, but for technical reasons I don’t need to bother you with, I would very much like command to be stopped after it has had CPU for a half-second or maybe a bit less.

A Linux-specific answer would be fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:50:47+00:00Added an answer on May 22, 2026 at 7:50 pm

    As other people said, you can’t do it with the standard built-in Bash commands.

    It is possible to create your own command to limit the elapsed time for a command (distinct from the actual CPU time used by the command; see also the comments from Rob, for which, thanks!). I’ve previously published on SO code to do timeouts after an integer number of elapsed seconds (so it is not directly an answer to your problem). However, you could (fairly) easily adapt the code to use sub-second resolution on the elapsed time and the POSIX facilities. The core interface is:

    timeout -t time [-s signal] cmd [args ...]
    

    To handle your requirements, it would simply need to recognize sub-second times and call the appropriate functions; it affects the internals far more than the externals.

    Theoretically (according to POSIX 2008), you should use the timer_create(), timer_settime() and timer_gettime() functions. These provide detailed control over which signal should be generated when the timer expires, etc. However, not all systems provide them (for example, MacOS X 10.6.7 does not document them). These use the headers <time.h> and <signal.h>, and struct itimerspec (and struct sigevent).

    However, in the short term, you may need to use the functions getitimer() and setitimer() instead, which POSIX 2008 marks as obsolescent (but which are available on MacOS X 10.6.7). These use the header <sys/time.h> and struct itimerval.

    To be portable, you may need to autoconfigure your program to deal with both these; you might also need to deal with Windows (which will undoubtedly provide an alternative interface). You probably fall back on alarm() and whole-second granularity timing if neither of the fine resolution signalling timer systems is available. Choose the timer_* functions over the *itimer functions if both are present – or simply test for timer_* first and use them if available.

    Be aware that if you set a timeout of 0.5 seconds with these functions, they guarantee a minimum elapsed time of 0.5 seconds – but it may be arbitrarily longer than the time because of scheduling issues. Note that there is a timer_getoverrun() to help establish how long the overrun was.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I limit my post-build events to running only for one type of
I'm using the MongoDB Java driver, and can't seem to get a query to
How can I limit the length of time an operation is allowed to take?
I only you can limit what a user can do via the user permissions
I'd like to create a plug-in architecture where I can limit an assemblies API
How can I limit a result set to n distinct values of a given
How can I limit a string's word count in XSLT 1.0?
How can i limit a foreach() statement? Say i only want it to run
Binding a List collection to a datagrid. How can you limit what properties will
How can a fixed character limit be imposed on a text field in Cocos2d?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.