Re: Run and Forget in Linux
- Posted by ags <eu at 531pi.co.nz>
Sep 30, 2005
cklester wrote:
>
> On my Linux box, I need one program ('A') to start another ('B'). Program 'A'
> needs to be able to close regardless of what 'B' does. Do I use system() for
> this?
>
> -=ck
> "Programming in a state of EUPHORIA."
> <a
> href="http://www.cklester.com/euphoria/">http://www.cklester.com/euphoria/</a>
>
From the Comments in system():
system() will start a new DOS or Linux/FreeBSD shell.
system() allows you to use command-line redirection of
standard input and output in the command string st.
So if it's using the shell, an ampersand at the end of your command string
should start the new program in the background--which is fine for X programs
since it should still display on the X display of the current environment
or for programs which have no output.
In this example, a.ex counts to 5, starts b.ex and keeps going until b.ex
creates a semaphore file in the /tmp directory.
<b>Program a.ex:</b>
#!/usr/local/euphoria/bin/exu
-- replace above with path to exu (run "which exu")
-- chmod +x a.ex
include misc.e -- for sleep()
-- Program A: Count to 5 then spawn program B and continue to count until
-- program B creates the file /tmp/stop_counting_A
atom i, go, fn
go = 1
i = 0
-- clear initial loop condition
system("rm /tmp/stop_counting_A", 2) --
-- main loop
while go do
puts(1, sprintf("%d ", i))
if i = 5 then
system("./b.ex &", 2) -- start b without clearing the screen
-- remove the & to see the difference
end if
sleep(1)
i = i + 1
-- check loop stop condition
fn = open("/tmp/stop_counting_A", "rb")
if fn != -1 then
go = 0 -- bail out since file exists
end if
end while
-- end program
<b>Program B:</b>
#!/usr/local/euphoria/bin/exu
-- program B: wait rand(10) seconds before creating /tmp/stop_counting_A
include misc.e -- for sleep()
atom w, fn
w = rand(10)
for i = 1 to w do
sleep(1) -- why not sleep(w)?, don't ask me ;)
end for
fn = open("/tmp/stop_counting_A", "wb")
close(fn) -- create empty file
-- end program
The only noticeable effect of starting program B is that the cursor briefly
goes to the bottom left of the screen (over a ssh session so probably not
noticeable on a real console).
ags
(lurking and too busy to touch even Euphoria :( )
|
Not Categorized, Please Help
|
|