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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:14:44+00:00 2026-06-05T16:14:44+00:00

There is a command (say $run_command), which has to be killed after timeout. The

  • 0

There is a command (say $run_command), which has to be killed after timeout. The solution is quite simple – I can just use timeout from coreutils or timeout3 from other stackoverflow topics. But my command receives it’s stdin from untar pipe smth like this

tar -xO -f "$1" | /usr/bin/time -f "%e" --output=$time_output -- $run_command

Where $run-command is my command, which execution time has also be measured (using the time utility).

So, the question is what is the best way to avoid including untarring time in the timeout utility?

  • 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-06-05T16:14:46+00:00Added an answer on June 5, 2026 at 4:14 pm

    In very simple form, you can kill the calling script like this:

    #!/bin/bash
    
    ( sleep $timeout_period && kill $$ ) &
    
    tar -xO -f "$1" | ...
    

    Of course, this is only an example; you’ll want to provide some insurance that $$ is still the same script when kill runs.

    This will of course kill the whole script, including time (which will be $timeout_period if the script was killed).

    UPDATE #1:

    Example using a tempfile.

    tmpfile=$(/usr/bin/mktemp /tmp/temp.XXXXX)
    
    tar -xO -f "$1" > $tmpfile
    trap "rm -f $tmpfile" 0 1 2 3 15
    
    /usr/bin/time -f "%e" --output=$time_output -- $run_command < $tmpfile
    

    Note that this is still subject to error due to the speed/performance of your filesystem.

    UPDATE #2:

    This adds the timeout function in addition to exempting tar time:

    (
      tmpfile=$(/usr/bin/mktemp /tmp/temp.XXXXX)
      tar -xO -f "$1" > $tmpfile
      trap "rm -f $tmpfile" 0 1 2 3 15
      /usr/bin/time -f "%e" --output=$time_output -- $run_command < $tmpfile
    ) &
    
    pid=$!
    
    ( sleep $timeout_period && kill $pid ) &
    
    wait %1
    

    The same potential issue in the first script segment exists; you’ll want to provide insurance that $$ is still what you think it before you kill it. Also, the signal will be sent to the shell wrapper, not directly to your command. You’ll have to test whether signals get passed through to your command as expected.

    Note also that this backgrounds the timeout/kill. The “wait” tells the script to wait until the first background process is finished, so either your command finishes by itself or it gets killed by the timeout … and then the script proceeds to anything after the wait. If the command finishes by itself, then that’s where you run into potential issues with $pid being recycled for another process. Solving that is left as an exercise for the reader. 🙂

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

Sidebar

Related Questions

There's a command in VIM where you can say how many chars to replace,
I have a simple .NET application which runs as Windows Service. Say it has
say I have two files: file1 and file2 is there a single command that
For example, when I say . .bashrc on my Linux command prompt, is there
Is there command to use on windows from java to make the computer sleep?
Is there a command which will print the path of the file in the
Is there a command I can run inside my SQL script so that it
Is there a way to create a command line tool which will help extensively
how do i use c# to run command prompt commands? Lets say i want
We have a simple java app which runs user requests (commands) on the command

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.