[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: system-question
From: |
Mats Jansson |
Subject: |
Re: system-question |
Date: |
Fri, 29 Oct 1999 09:08:14 +0200 |
Thanks Joao!
You introduced the command 'fork' to me!
Unfortunately, a new problem appeared. When I'm killing emacs from the
octave-prompt, everything seems to work. But when I'm killing it from
a function, it becomes a zombie-process.
Does anyone have a solution?
Thanks
Mats
address@hidden ~]$ octave
GNU Octave, version 2.0.14 (i386-redhat-linux-gnu).
Copyright (C) 1996, 1997, 1998, 1999 John W. Eaton.
This is free software with ABSOLUTELY NO WARRANTY.
For details, type `warranty'.
octave:1> pid=launch ("emacs","dummy")
pid = 18807
octave:2> system ("ps f")
PID TTY STAT TIME COMMAND
18296 pts/3 S 0:00 -csh
18804 pts/3 S 0:00 octave
18807 pts/3 S 0:01 \_ emacs dummy
18808 pts/3 R 0:00 \_ ps f
ans = 0
octave:3> system (["kill ", num2str(pid)])
ans = 0
octave:4> system ("ps f")
PID TTY STAT TIME COMMAND
18296 pts/3 S 0:00 -csh
18804 pts/3 S 0:00 octave
18810 pts/3 R 0:00 \_ ps f
ans = 0
octave:5> function retval=kill(pid)
> retval=system (["kill ", num2str(pid)]);
> endfunction
octave:6> pid=launch ("emacs","dummy")
pid = 18811
octave:7> system ("ps f")
PID TTY STAT TIME COMMAND
18296 pts/3 S 0:00 -csh
18804 pts/3 S 0:00 octave
18811 pts/3 S 0:01 \_ emacs dummy
18812 pts/3 R 0:00 \_ ps f
ans = 0
octave:8> kill (pid)
ans =
octave:9> system ("ps f")
PID TTY STAT TIME COMMAND
18296 pts/3 S 0:00 -csh
18804 pts/3 S 0:00 octave
18811 pts/3 Z 0:01 \_ [emacs <defunct>]
18814 pts/3 R 0:00 \_ ps f
ans = 0
octave:10>
Joao Cardoso wrote:
> Mats Jansson wrote:
>
>> Hi!
>>
>> I want to start a program in the background from octave. I want to be
>> able to check if the program is still running and I want to be able to
>> close the program from octave.
>>
>> My idea was to start the program (in this case emacs) with
>>
>> pid = system("emacs", 1, "async").
>>
>> To check if the program is still running I could use 'system("ps")',
>> to close the program I could use 'system(["kill ", num2str(pid)])'.
>>
>> system("emacs", 1, "async") returns a PID to a new octave-process, and
>> not to the emacs-process, so I don't know the PID to the process to
>> kill.
>
> you must 'exec' after fork, so the exec program (emacs) will substitute
> the forked one (octave).
> somethink like:
>
> function pid = launch (command, args)
>
> # pid = launch (command, args)
> #
> # this is similar to system(async), (fork/exec really)
> # but it first closes stdout and stderr to avoid spurious messages
>
> if (nargin == 1 || nargin == 2)
>
> if (nargin == 1)
> args = "";
> endif
>
> if (isstr (command))
> pid = fork ();
> fp = fopen("/dev/null","w+");
> if (pid == 0)
> # dup2 (fp, stdin); # can't close this one...
>
> dup2 (fp, stdout);
> dup2 (fp, stderr);
> # on_signal(2,"SIG_IGN","");
> if (exec (command, args) < 0)
> error ("launch: unable to start process
> `%s'", c
> ommand);
> exit (0);
> endif
> else
> fclose(fp);
> return;
> endif
> else
> error ("launch: file name must be a string");
> endif
> else
> usage ("launch (command, args)");
> endif
>
> endfunction
---------------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL. To ensure
that development continues, see www.che.wisc.edu/octave/giftform.html
Instructions for unsubscribing: www.che.wisc.edu/octave/archive.html
---------------------------------------------------------------------