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

  • Home
  • SEARCH
  • 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 581671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:36:16+00:00 2026-05-13T14:36:16+00:00

I have a long running BASH script that I am running under CYGWIN on

  • 0

I have a long running BASH script that I am running under CYGWIN on Windows.

I would like to limit the script to run for 30 seconds, and automatically terminate if it exceeds this limit. Ideally, I’d like to be able to do this to any command.

For example:

$ limittime -t 30 'myscript.sh'

or

$ limittime -t 30 'grep func *.c'

Under cygwin the ulimit command doesn’t seem to work.

  • 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-13T14:36:16+00:00Added an answer on May 13, 2026 at 2:36 pm

    See the http://www.pixelbeat.org/scripts/timeout script the functionality of which has been integrated into newer coreutils:

    #!/bin/sh
    
    # Execute a command with a timeout
    
    # License: LGPLv2
    # Author:
    #    http://www.pixelbeat.org/
    # Notes:
    #    Note there is a timeout command packaged with coreutils since v7.0
    #    If the timeout occurs the exit status is 124.
    #    There is an asynchronous (and buggy) equivalent of this
    #    script packaged with bash (under /usr/share/doc/ in my distro),
    #    which I only noticed after writing this.
    #    I noticed later again that there is a C equivalent of this packaged
    #    with satan by Wietse Venema, and copied to forensics by Dan Farmer.
    # Changes:
    #    V1.0, Nov  3 2006, Initial release
    #    V1.1, Nov 20 2007, Brad Greenlee <brad@footle.org>
    #                       Make more portable by using the 'CHLD'
    #                       signal spec rather than 17.
    #    V1.3, Oct 29 2009, Ján Sáreník <jasan@x31.com>
    #                       Even though this runs under dash,ksh etc.
    #                       it doesn't actually timeout. So enforce bash for now.
    #                       Also change exit on timeout from 128 to 124
    #                       to match coreutils.
    #    V2.0, Oct 30 2009, Ján Sáreník <jasan@x31.com>
    #                       Rewritten to cover compatibility with other
    #                       Bourne shell implementations (pdksh, dash)
    
    if [ "$#" -lt "2" ]; then
        echo "Usage:   `basename $0` timeout_in_seconds command" >&2
        echo "Example: `basename $0` 2 sleep 3 || echo timeout" >&2
        exit 1
    fi
    
    cleanup()
    {
        trap - ALRM               #reset handler to default
        kill -ALRM $a 2>/dev/null #stop timer subshell if running
        kill $! 2>/dev/null &&    #kill last job
          exit 124                #exit with 124 if it was running
    }
    
    watchit()
    {
        trap "cleanup" ALRM
        sleep $1& wait
        kill -ALRM $$
    }
    
    watchit $1& a=$!         #start the timeout
    shift                    #first param was timeout for sleep
    trap "cleanup" ALRM INT  #cleanup after timeout
    "$@"& wait $!; RET=$?    #start the job wait for it and save its return value
    kill -ALRM $a            #send ALRM signal to watchit
    wait $a                  #wait for watchit to finish cleanup
    exit $RET                #return the value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 309k
  • Answers 309k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try creating the table in HTML Clipboard format, add to… May 13, 2026 at 9:58 pm
  • Editorial Team
    Editorial Team added an answer A single method in a Java class may be at… May 13, 2026 at 9:58 pm
  • Editorial Team
    Editorial Team added an answer You cannot do it using UITextView, or any others. When… May 13, 2026 at 9:58 pm

Related Questions

My bash scripting is weak. I want to create a script that filters and
I have a java CLI script that converts rgb names to hexcodes (e.g. 144
I have the following situation: There is a windows folder that has been mounted
I have a Perl script that does a fork/exec to start another tool in
Possible Duplicate: Quick-and-dirty way to ensure only one instance of a shell script is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.