<br><br><div class="gmail_quote">On Wed, Jun 23, 2010 at 3:01 AM, Eric Battersby <span dir="ltr"><<a href="mailto:gyre-Ja3L+HSX0kI@public.gmane.org">gyre-Ja3L+HSX0kI@public.gmane.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div><div></div><div class="h5">On Tue, 22 Jun 2010, Matt Price wrote:<br>
<br>
> On Tue, Jun 22, 2010 at 3:37 PM, Chris F.A. Johnson <<a href="mailto:chris-E7bvbYbpR6jSUeElwK9/Pw@public.gmane.org">chris-E7bvbYbpR6jSUeElwK9/Pw@public.gmane.org</a>><br>
> wrote:<br>
>       On Tue, 22 Jun 2010, Matt Price wrote:<br>
><br>
>       > hi,<br>
>       ><br>
>       > quick scripting question.  I have an irritating emacs bug, in<br>
>       which<br>
>       > emacs sometimes hangs when the network's disrupted.  To deal<br>
>       with this<br>
>       > i have just send a command via emacsclient to the running<br>
>       server<br>
>       > before i suspend, which solves a solid 90% of my problems.<br>
>        but<br>
>       > sometimes emacs is already hung when i want to suspend!  in<br>
>       that case,<br>
>       > my script hangs too and the suspend event never takes place,<br>
>       which is<br>
>       > almost always worse since it causes everything to lose data,<br>
>       not just<br>
>       > emacs.  here's my tiny function:<br>
>       ><br>
>       > suspend_wl()<br>
>       > {<br>
>       >       # Get WL to go offline<br>
>       >         if [-f /tmp/emacs1000/server]<br>
>       >           then<br>
>       >             /usr/bin/emacsclient --socket-name<br>
>       /tmp/emacs1000/server<br>
>       > --eval "(wl-toggle-plugged 'off)"<br>
>       >       fi<br>
>       > }<br>
>       > is there a "try" or similar command i can use around the<br>
>       emacsclient<br>
>       > command, to just continue if things are taking too long?<br>
><br>
> wait=666       ## seconds before timing out<br>
> suspend_wl &   ## put function into the background<br>
> sleep $wait    ## wait<br>
> kill $!        ## kill last background process<br>
><br>
> wouldn't that guarantee that you have to wait $wait seconds before suspend?<br>
> hmm.. is there no way to, say, test once a second to see whether the job has<br>
> finished?<br>
<br>
</div></div>You don't need to poll.<br>
If you must do it in Shell, what about this?:<br>
<br>
  trap "kill %1 %2 2>/dev/null" CHLD; suspend_wl &  sleep $wait<br>
<br>
It will take the lesser of $wait or how long 'suspend_wl' runs.<br>
<br>
## test timeout<br>
[~]$ time -p (set -m; trap "kill %1 %2 2>/dev/null" CHLD; sleep 9 &  sleep 2)<br>
real 2.00<br>
...<br>
## test normal completion<br>
[~]$ time -p (set -m; trap "kill %1 %2 2>/dev/null" CHLD; sleep 2 &  sleep 9)<br>
real 2.00<br>
...<br>
<br></blockquote><div>hmm, cool.  can you tell me more about what trap does?  it doesn't seem to have a man page or much of a --help -- i htink it operates at a lower level than i'm used to.  <br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

If your background task can spawn off other children, I would<br>
recommend using Perl or C and creating a new process group for<br>
the children.<br>
<font color="#888888"><br></font></blockquote><div><br>... if i oculd learn them...  but i think keeping it in shell is simpler for now.  thanks again!<br>matt <br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<font color="#888888">
--<br>
Eric B.<br>
</font><div><div></div><div class="h5">--<br>
The Toronto Linux Users Group.      Meetings: <a href="http://gtalug.org/" target="_blank">http://gtalug.org/</a><br>
TLUG requests: Linux topics, No HTML, wrap text below 80 columns<br>
How to UNSUBSCRIBE: <a href="http://gtalug.org/wiki/Mailing_lists" target="_blank">http://gtalug.org/wiki/Mailing_lists</a><br>
</div></div></blockquote></div><br>