|
|
Please consider the following example wnich is hopefully self-explanatory and introduces thr functions `uiop:launch-program`, `uiop:process-alive-p`, and `uiop:terminate-process` as well as `uiop:wait-process` and the fact that programs should always be waited for at least once (to make sure their resources are released) and have `uiop:close-streams` called on them:
|
|
|
Please consider the following example which is hopefully self-explanatory and introduces the functions `launch-program`, `process-alive-p`, and `terminate-process` as well as `wait-process` and the fact that programs should always be waited for at least once (to make sure their resources are released) and have `close-streams` called on them:
|
|
|
```common-lisp
|
|
|
(require :asdf)
|
|
|
|
... | ... | @@ -51,8 +51,7 @@ Please consider the following example wnich is hopefully self-explanatory and in |
|
|
(format t "7s-sleeper still sleeping? ~a (expected: T)~%~%"
|
|
|
(bool->string (uiop:process-alive-p p7)))
|
|
|
|
|
|
(format t "Finally, killing the last remaining process and exiting~%")
|
|
|
(uiop:terminate-process p7)
|
|
|
(format t "Finally, waiting for the last remaining process and exiting~%")
|
|
|
(wait-and-close-streams p7))
|
|
|
```
|
|
|
It should generate the following output:
|
... | ... | @@ -76,8 +75,17 @@ Terminating the 9s-sleeper now, then waiting for it! |
|
|
# Checking: Are the others still sleeping?
|
|
|
7s-sleeper still sleeping? T (expected: T)
|
|
|
|
|
|
Finally, killing the last remaining process and exiting
|
|
|
Finally, waiting for the last remaining process and exiting
|
|
|
```
|
|
|
and return with an exit status of 0.
|
|
|
and return a code of 0.
|
|
|
|
|
|
A few more features of `launch-program` are shown in [delta.lisp](https://github.com/epipping/delta-lisp/blob/master/delta.lisp) of [delta-lisp](https://github.com/epipping/delta-lisp). |
|
|
\ No newline at end of file |
|
|
The 7s-sleeper and the 9s-sleeper went from alive to
|
|
|
not-alive in different ways here: the former exited while
|
|
|
the latter was terminated, e.g. by having a signal sent to
|
|
|
it. This distinction can be relevant. That's why `wait-process`
|
|
|
exposes it whenever possible: If a process is killed by signal
|
|
|
15, its return code will be 128+15=143. To distinguish that
|
|
|
from a regular exit with return code 143,
|
|
|
`wait-process` will return the two values 143 and 15 whenever possible.
|
|
|
A clean exit with return code 0 can still always simply be checked for
|
|
|
via `(= 0 (wait-process))`. |
|
|
\ No newline at end of file |