From: Paul Carpenter on
I am building a GUI application for Linux using GUIDE... I need to launch a Linux process using 'unix' (or 'system') command and wait for a return. However, I *must* be able to terminate this operation via a pushbutton in the GUI because sometimes this operation takes a long time (and safety can be a factor). I am an newbie to Matlab and GUIDE, but it seems the executable is multi-threaded such that this can be done. So when I click on "Stop" button I expect to either: (a) use built-in Matlab call to directly terminate the first 'system' call, or (b) use another 'system' call with the 'kill' command and process ID (Linux) of the first process launched via 'system' in order to terminate it. Can (a) and/or (b) be done? Are there any caveats?
Thank you.
From: Jan Simon on
Dear Paul,

> I am building a GUI application for Linux using GUIDE... I need to launch a Linux process using 'unix' (or 'system') command and wait for a return. However, I *must* be able to terminate this operation via a pushbutton in the GUI because sometimes this operation takes a long time (and safety can be a factor).

How do the system process signal, that it is ready?
It is not easy to get the PID for the kill process. Can you modify the calle program such, that it replies the PID to Matlab, when it is started(!) ?

Kind regards, Jan
From: Walter Roberson on
Paul Carpenter wrote:
> I am building a GUI application for Linux using GUIDE... I need to
> launch a Linux process using 'unix' (or 'system') command and wait for a
> return. However, I *must* be able to terminate this operation via a
> pushbutton in the GUI because sometimes this operation takes a long time
> (and safety can be a factor). I am an newbie to Matlab and GUIDE, but
> it seems the executable is multi-threaded such that this can be done.
> So when I click on "Stop" button I expect to either: (a) use built-in
> Matlab call to directly terminate the first 'system' call, or (b) use
> another 'system' call with the 'kill' command and process ID (Linux) of
> the first process launched via 'system' in order to terminate it. Can
> (a) and/or (b) be done? Are there any caveats?

[status, result] = system('The Linux command &');

Result would then probably be a string containing the PID.

If you had specified that Matlab needed to be able to get results back
from the process then the procedure would have been different and less
portable.
From: Paul Carpenter on
"Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <i37m6u$ahq$1(a)fred.mathworks.com>...
> Dear Paul,
>
> > I am building a GUI application for Linux using GUIDE... I need to launch a Linux process using 'unix' (or 'system') command and wait for a return. However, I *must* be able to terminate this operation via a pushbutton in the GUI because sometimes this operation takes a long time (and safety can be a factor).
>
> How do the system process signal, that it is ready?
> It is not easy to get the PID for the kill process. Can you modify the calle program such, that it replies the PID to Matlab, when it is started(!) ?
>
> Kind regards, Jan

Hi Jan, thanks for the reply...

I found that in Linux I can use "killall -INT <process filename>" to send a signal to the running process, which can clean up and exit, return necessary status and response information to Matlab via the system(cmd) command.
From: Paul Carpenter on
Walter Roberson <roberson(a)hushmail.com> wrote in message <ERJ5o.48467$3%3.12254(a)newsfe23.iad>...
> Paul Carpenter wrote:
> > I am building a GUI application for Linux using GUIDE... I need to
> > launch a Linux process using 'unix' (or 'system') command and wait for a
> > return. However, I *must* be able to terminate this operation via a
> > pushbutton in the GUI because sometimes this operation takes a long time
> > (and safety can be a factor). I am an newbie to Matlab and GUIDE, but
> > it seems the executable is multi-threaded such that this can be done.
> > So when I click on "Stop" button I expect to either: (a) use built-in
> > Matlab call to directly terminate the first 'system' call, or (b) use
> > another 'system' call with the 'kill' command and process ID (Linux) of
> > the first process launched via 'system' in order to terminate it. Can
> > (a) and/or (b) be done? Are there any caveats?
>
> [status, result] = system('The Linux command &');
>
> Result would then probably be a string containing the PID.
>
> If you had specified that Matlab needed to be able to get results back
> from the process then the procedure would have been different and less
> portable.

Thank you, Walter, for your reply....

I had considered using '&' in the system command, but then I do not believe that Matlab would wait for the status and result response, correct? I do want to wait for these... However, what I really want is for Matlab to respond to a button press while the current command is executing, which causes another system() command to run that sends a signal to the executing process, causing it to clean-up and exit gracefully. When I click on the "Stop" button while the first command is executing it seems like the GUI takes the press, but it appears that the processing of the callback happens after the first command is completed, thus defeating the purpose of my Stop button..... So what I'd really like to know is that Matlab GUI is multi-threaded and can thus handle processing more than one linux shell at a time. I hope this is not a limitation of Matlab because if it is, I cannot see it ever
becoming a widely adopted platform for production quality user interfaces.