Timeline for Timing out in a shell script
Current License: CC BY-SA 3.0
21 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 13, 2017 at 12:37 | history | edited | CommunityBot |
replaced http://unix.stackexchange.com/ with https://unix.stackexchange.com/
|
|
| Feb 1, 2016 at 12:57 | history | edited | Stéphane Gimenez | CC BY-SA 3.0 |
added 3 characters in body
|
| Dec 18, 2015 at 16:57 | history | edited | Gilles 'SO- stop being evil' | CC BY-SA 3.0 |
http://unix.stackexchange.com/a/250241
|
| Feb 13, 2015 at 15:40 | comment | added | Gabor Csardi |
Unfortunately it does not work on OSX, probably their bash is too old: GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin14) Copyright (C) 2007 Free Software Foundation, Inc.
|
|
| Jul 18, 2012 at 23:36 | vote | accept | Gilles 'SO- stop being evil' | ||
| Jun 14, 2012 at 19:46 | comment | added | Stéphane Gimenez | @Zac: It's not possible to reverse the ordering in the original case, because only the first process get access to stdin. | |
| Jun 14, 2012 at 15:32 | comment | added | Zac B | D'oh! Also, for brevity's sake, you can reverse the ordering of the two internal program groups, and then you don't have to do any redirection. Gorgeous solution, btw. | |
| Jun 13, 2012 at 19:36 | comment | added | Stéphane Gimenez |
@Zac: You forgot the 1>&3 redirection after the echo.
|
|
| Jun 13, 2012 at 19:31 | comment | added | Zac B |
Sure, but if I run { { echo boo; kill 0; } | { sleep 2; kill 0; } } 3>&1, I don't see "boo" printed to stdout.
|
|
| Jun 13, 2012 at 19:12 | comment | added | Stéphane Gimenez | @Zac: Don't tell me you also need to run commands on 20th century systems? You can just remove the variable assignation if you don't want to collect the output. | |
| Jun 13, 2012 at 15:54 | comment | added | Zac B | Is there an easy way to adapt this method such that the output-producing command outputs to the invoking terminal in real-time? In the above example, output is only visible after timeout/completion via the variable whose value was set to the output of the double-program-group magic. | |
| Aug 20, 2011 at 19:05 | comment | added | Gilles 'SO- stop being evil' | I really like the trick, so I'm awarding the bounty. It seems to work on Linux, I haven't had time to test it on other systems yet. | |
| Aug 20, 2011 at 19:04 | history | bounty awarded | Gilles 'SO- stop being evil' | ||
| Aug 16, 2011 at 21:07 | comment | added | Stéphane Gimenez | @Gilles: See my edit. Not pretty and I can't tell about portability. | |
| Aug 16, 2011 at 21:01 | history | edited | Stéphane Gimenez | CC BY-SA 3.0 |
setpgrp using the shell…
|
| Aug 16, 2011 at 15:06 | comment | added | Stéphane Gimenez |
@Gilles: Eek! couldn't find a way to setprgp() without setsid for now :-(
|
|
| Aug 16, 2011 at 14:09 | comment | added | Gilles 'SO- stop being evil' |
Unfortunately, this fails spectacularly as soon as I put this in a script: the pipeline in the command substitution does not run in its own process group, and kill 0 ends up killing the script's caller as well. Is there a portable way to force the pipeline into its own process group?
|
|
| Aug 16, 2011 at 1:06 | history | edited | Stéphane Gimenez | CC BY-SA 3.0 |
add a note
|
| Aug 14, 2011 at 18:50 | comment | added | Gilles 'SO- stop being evil' | I quite like this, I hadn't thought of using a process group that way. It's pretty simple and there's no race condition. I need to test it for portability some more, but this looks like a winner. | |
| Aug 14, 2011 at 18:48 | history | edited | Gilles 'SO- stop being evil' | CC BY-SA 3.0 |
don't mix up stderr with legitimate output; added explanation
|
| Aug 14, 2011 at 3:17 | history | answered | Stéphane Gimenez | CC BY-SA 3.0 |