/*-------------------------------------------------------------------- * Function: stop_processes * Returns: t or nil * Description: Gives us the option of stopping a single child process or * multiple child processes. Calls kill_child() to actually * stop a process. *------------------------------------------------------------------*/ function stop_processes(prog? = nil, process_name = nil) { try {
The code for this function is wrapped in a Gamma try/catch block, to demonstrate how the process can be protected from errors arising from this function.
if(process_name != nil) { /* Kill a specified child, looking it up in the list of known * children. We look it up by name, even though the association * list is by process ID. This means that we have to traverse * the list of children ourselves to find the proper name. */ with x in Children do { if (cadr (x) == process_name) { child = x; if (child) kill_child(child, prog, process_name); } }
The Gamma statements and functions used here are the with statement to walk a list and perform an action, the cadr and car functions to find those parts of a list, and the kill function to send a signal to a process.
} else /* Kill all the children. */ with child in Children do { prog = car(cdddr(child)); process_name = cadr(child); if(prog && process_name) { kill_child(child, prog, process_name); usleep(10000); } } } catch { princ("Error:\n", _error_stack_, "\n"); } }
Copyright © 1995-2010 by Cogent Real-Time Systems, Inc. All rights reserved.