From help-octave-request at bevo dot che dot wisc dot edu Wed Oct 27 08:25:29 1999 Subject: system-question From: Mats Jansson To: help-octave at bevo dot che dot wisc dot edu Date: Wed, 27 Oct 1999 15:24:42 +0200 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. Does anybody know how to solve the problem? Thanks! Mats [mj at pctkj ~]$ octave --norc 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> system("ps f") PID TTY STAT TIME COMMAND 24927 pts/7 S 0:00 -csh 24987 pts/7 S 0:00 octave --norc 24988 pts/7 R 0:00 \_ ps f ans = 0 octave:2> pid=system("emacs",1,"async") pid = 25024 octave:3> system("ps f") PID TTY STAT TIME COMMAND 24927 pts/7 S 0:00 -csh 24987 pts/7 S 0:00 octave --norc 25024 pts/7 S 0:00 \_ octave --norc 25025 pts/7 S 0:03 | \_ emacs 25031 pts/7 R 0:00 \_ ps f ans = 0 octave:4> ## emacs are closed (ctrl-X ctrl-C) octave:4> system("ps f") PID TTY STAT TIME COMMAND 24927 pts/7 S 0:00 -csh 24987 pts/7 S 0:00 octave --norc 25032 pts/7 R 0:00 \_ ps f ans = 0 octave:5> ## This works fine, I can check if pid is still present octave:5> pid=system("emacs",1,"async") pid = 25034 octave:6> system("ps f") PID TTY STAT TIME COMMAND 24927 pts/7 S 0:00 -csh 24987 pts/7 S 0:00 octave --norc 25034 pts/7 S 0:00 \_ octave --norc 25035 pts/7 S 0:03 | \_ emacs 25036 pts/7 R 0:00 \_ ps f ans = 0 octave:7> system("kill -9 25034") ans = 0 octave:8> system("ps f") PID TTY STAT TIME COMMAND 24927 pts/7 S 0:00 -csh 24987 pts/7 S 0:00 octave --norc 25038 pts/7 R 0:00 \_ ps f 25035 pts/7 S 0:03 emacs ans = 0 octave:9> ## Emacs is still there, I want it to disappear! --------------------------------------------------------------------- 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 ---------------------------------------------------------------------