View Single Post
  #3   (View Single Post)  
Old 25th March 2009
TerryP's Avatar
TerryP TerryP is offline
Arp Constable
 
Join Date: May 2008
Location: USofA
Posts: 1,547
Default

I've rarely known super simple examples to display efficient programming practices ;-) (the example shouldn't even require a fork in some cases)



Quote:
Originally Posted by robbak View Post
I also am not sure if shell variables could be used in this way: the called program would have it's own environment, so $ALIVE in the calling process would remain untouched.
Aye, it would be a "forked" variable of sorts. The shell would execute the fork built in; fork itself and set the $ALIVE and $? variables accordingly within their process before reading the next line of the script; to the parent $ALIVE represents the child's status. When the parent receives SIGCHLD, it would change the value of $ALIVE so that the shell script would know it's kid finished, should it care.


The problem (in my sleep starved) mind at the moment, would be how to make tpsh go back from the signal handler to where it was (in the examples case, likely inside the while $ALIVE loop) before the child exited, and interrupted the script. Best guess that I can think of without sleeping on it, is things like the while loop and individual lines would need to block signals until the end of the loop/line has been handled by the shell, and then re-execute the appropriate function or something like that after getting SIGCHLD; which would have to know how to restore it's place form saved state. (which really does not sound like fun writing, come to think of it) And is probably easier to think about then write outside of asm, assuming I'm still thinking semi-clearly at this time of night/morning in the first place.

Either way... time for crashing to a pillow.


Quote:
Originally Posted by robbak View Post
My syntax would look more like this. ... This (or something similar) could probably be done using current shell commands: & of a process, and check/wait on it's job number. (Maybe you'd have to do that with a busywait, though.
it's possible to do an async launch&, and although I've never used it modern shells have a built-in wait [job] command for whatever it's actually worth; but afaik no way to execute 1 shell script in 2 processes at the same time, without using a temporary shared file/named pipe in some equally inefficient ways to coordinate them.


(For some reason, I think I'll be having multi-threaded nightmares >_<)
__________________
My Journal

Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''.
Reply With Quote