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 6387663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:10:48+00:00 2026-05-25T03:10:48+00:00

Ok, I need to write a code that calls a script, and if the

  • 0

Ok, I need to write a code that calls a script, and if the operation in script hangs, terminates the process.

The preferred language is Python, but I’m also looking through C and bash script documentation too.

Seems like an easy problem, but I can’t decide on the best solution.

From research so far:

  • Python: Has some weird threading model where the virtual machine uses
    one thread at a time, won’t work?
  • C: The preferred solution so far seems to use SIGALARM + fork +
    execl. But SIGALARM is not heap safe, so it can trash everything?
  • Bash: timeout program? Not standard on all distros?

Since I’m a newbie to Linux, I’m probably unaware of 500 different gotchas with those functions, so can anyone tell me what’s the safest and cleanest way?

  • 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-25T03:10:48+00:00Added an answer on May 25, 2026 at 3:10 am

    In bash you can do something similar to this:

    1. start the script/program in background with &
    2. get the process id of the background process
    3. sleep for some time
    4. and then kill the process (if it is finished you cannot kill it) or you can check if the process is still live and then to kill it.

    Example:

    sh long_time_script.sh &
    pid=$!
    sleep 30s
    kill $pid
    

    you can even try to use trap 'script_stopped $pid' SIGCHLD – see the bash man for more info.

    UPDATE: I found other command timeout. It does exactly what you need – runs a command with a time limit. Example:

    timeout 10s sleep 15s
    

    will kill the sleep after 10 seconds.

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

Sidebar

Related Questions

I need to write some junit tests on Java code that calls Math.random() .
I need to write code that picks up PGP-encrypted files from an FTP location
I need to write the code that would format the value according to the
I need to write some code that would loop though all rows of a
I've got a bunch of legacy code that I need to write unit tests
I need to write a delegate function that can 'wrap' some while/try/catch code around
Greetings. I have written a little python script that calls MySQL in a subprocess.
I've wrote a python script that need to pass millions of items to a
I've got the following bit of code (that another developer wrote) that I need
I need to write code to determine if 2 strings match when one of

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.