-
Notifications
You must be signed in to change notification settings - Fork 13
Notification when a process finishes
Brian Lau edited this page May 22, 2017
·
2 revisions
processManager objects issue a notification when their processes exit. This is useful, for example, when something should be done when a process finishes. Below is a minimal example of listening for the exit notification (download exampleListener.m):
if ispc
cmd = 'ping -n5 www.google.com';
else
cmd = 'ping -c5 www.google.com';
end
% Create an object and attach the listener
p = processManager('id','ping','command',cmd);
addlistener(p.state,'exit',@exitHandler);
where the listener callback is defined as:
function exitHandler(src,data)
fprintf('Listener notified!\n');
fprintf('Process %s exited with exitValue = %g\n',src.id,src.exitValue);
fprintf('Event name %s\n',data.EventName);
end
Events are handled through the processState object, which instantiated for each processManager instance. More information can be found in the Matlab documentation.