process.texi 4.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. @node POSIX processes
  2. @section Processes
  3. @stindex posix-processes
  4. The procedures described in this section control the creation of
  5. subprocesses and the execution of programs. They exported by both the
  6. @code{posix-processes} and @code{posix} structures.
  7. @cindex forking
  8. @cindex process forking
  9. @cindex POSIX @code{fork}
  10. @deffn procedure fork @returns{} process id or @code{#f}
  11. @deffnx procedure fork-and-forget thunk @returns{} unspecified
  12. @code{Fork} creates a new child process. In the parent process, it
  13. returns the child's process id; in the child process, it returns
  14. @code{#f}. @code{Fork-and-forget} calls @var{thunk} in a new process;
  15. no process id is returned. @code{Fork-and-forget} uses an intermediate
  16. process to avoid creating a zombie.
  17. @end deffn
  18. @cindex process ids
  19. @cindex POSIX process ids
  20. @deffn procedure process-id? object @returns{} boolean
  21. @deffnx procedure process-id=? pid@suba{a} pid@suba{b} @returns{} boolean
  22. @deffnx procedure process-id->integer pid @returns{} integer
  23. @deffnx procedure integer->process-id integer @returns{} pid
  24. @code{Process-id?} is the disjoint type predicate for process ids.
  25. @code{Process-id=?} tests whether two process ids are the same.
  26. @code{Process-id->integer} & @code{integer->process-id} convert between
  27. Scheme48's opaque process id type and POSIX process id integers.
  28. @end deffn
  29. @cindex process termination
  30. @cindex POSIX process termination
  31. @cindex waiting for POSIX processes
  32. @deffn procedure process-id-exit-status pid @returns{} integer or @code{#f}
  33. @deffnx procedure process-id-terminating-signal pid @returns{} signal or @code{#f}
  34. @deffnx procedure wait-for-child-process pid @returns{} unspecified
  35. If the process identified by @var{pid} exited normally or is running,
  36. @code{process-id-exit-status} and @code{process-id-terminating-signal}
  37. will both return @code{#f}. If, however, it terminated abnormally,
  38. @code{process-id-exit-status} returns its exit status, and if it exited
  39. due to a signal then @code{process-id-terminating-signal} returns the
  40. signal due to which it exited. @code{Wait-for-child-process} blocks
  41. the current process until the process identified by @var{pid} has
  42. terminated. Scheme48 may reap child processes before the user requests
  43. their exit status, but it does not always do so.
  44. @end deffn
  45. @cindex exiting processes
  46. @cindex POSIX process exiting
  47. @deffn procedure exit status @returns{} does not return
  48. Terminates the current process with the integer @var{status} as its
  49. exit status.
  50. @end deffn
  51. @cindex executing processes
  52. @cindex POSIX @code{exec}
  53. @deffn procedure exec program argument @dots{} @returns{} does not return
  54. @deffnx procedure exec-with-environment program env argument @dots{} @returns{} does not return
  55. @deffnx procedure exec-file filename argument @dots{} @returns{} does not return
  56. @deffnx procedure exec-file-with-environment filename env argument @dots{} @returns{} does not return
  57. These all replace the current program with a new one. They differ in
  58. how the program is found and what process environment the program
  59. should receive. @code{Exec} & @code{exec-with-environment} look up
  60. the program in the search path (the @code{PATH} environment variable),
  61. while @code{exec-file} & @code{exec-file-with-environment} execute a
  62. particular file. The environment is either inherited from the
  63. current process, in the cases of @code{exec} & @code{exec-file}, or
  64. explicitly specified, in the cases of @code{exec-with-environment} &
  65. @code{exec-file-with-environment}. @var{Program}, @var{filename}, &
  66. all @var{argument}s should be strings. @var{Env} should be a list of
  67. strings of the form @code{"@var{name}=@var{value}"}. When the new
  68. program is invoked, its arguments consist of the program name prepended
  69. to the remaining specified arguments.
  70. @end deffn
  71. @deffn procedure exec-with-alias name lookup? maybe-env arguments @returns{} does not return
  72. General omnibus procedure that subsumes the other @code{exec} variants.
  73. @var{Name} is looked up in the search path if @var{lookup?} is true or
  74. used as an ordinary filename if it is false. @var{Maybe-env} is either
  75. @code{#f}, in which case the new program's environment should be
  76. inherited from the current process, or a list of strings of the above
  77. form for environments, which specifies the new program's environment.
  78. @var{Arguments} is a list of @emph{all} of the program's arguments;
  79. @code{exec-with-alias} does @emph{not} prepend @var{name} to that list
  80. (hence @code{-with-alias}).
  81. @end deffn