26 Subprocesses (BC)

► |  | Inside: Racket C API

I | Inside Racket CS
II | Inside Racket BC (3m and CGC)
III | Appendices
| Index

▼ | II | Inside Racket BC (3m and CGC)

8 | Overview (BC)
9 | Embedding into a Program (BC)
10 | Writing Racket Extensions (BC)
11 | Values and Types (BC)
12 | Memory Allocation (BC)
13 | Namespaces and Modules (BC)
14 | Procedures (BC)
15 | Evaluation (BC)
16 | Exceptions and Escape Continuations (BC)
17 | Threads (BC)
18 | Parameterizations (BC)
19 | Continuation Marks (BC)
20 | String Encodings (BC)
21 | Bignums, Rationals, and Complex Numbers (BC)
22 | Ports and the Filesystem (BC)
23 | Structures (BC)
24 | Security Guards (BC)
25 | Custodians (BC)
26 | Subprocesses (BC)
27 | Miscellaneous Utilities (BC)

top contents ← prev up next →

### 26`` Subprocesses (BC)🔗ℹ

On Unix and Mac OS, subprocess handling involves fork, waitpid, and SIGCHLD, which creates a variety of issues within an embedding application. On Windows, subprocess handling is more straightforward, since no fork is required, and since Windows provides an abstraction that is a close fit to Racket’s subprocess values.

After Racket creates a subprocess via subprocess (or system, process, etc.), it periodically polls the process status using waitpid. If the process is created as its own group, then the call to waitpid uses the created subprocess’s process ID; for all other subprocesses, polling uses a single call to waitpid with the first argument as 0. Using 0, in particular, can interfere with other libraries in an embedding context, so Racket refrains from calling waitpid if no subprocesses are pending.

Racket may or may not rely on a SIGCHLD handler, and it may or may not block SIGCHLD. Currently, when Racket is compiled to support places, Racket blocks SIGCHLD on start up with the expectation that all created threads have SIGCHLD blocked. When Racket is not compiled to support places, then a SIGCHLD handler is installed.

Using fork in an application that embeds Racket is problematic for several reasons: Racket may install a SIGALRM handler and schedule alarms to implement context switches, it may have file descriptors open that should be closed in a child process, and it may have changed the disposition of signals such as SIGCHLD. Consequently, embedding Racket in a process that forks is technically not supported; in the future, Racket may provide better support for such applications.

top contents ← prev up next →