kproc 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. .TH KPROC 9
  2. .SH NAME
  3. kproc, pexit, postnote \- kernel process creation, termination and interrupt
  4. .SH SYNOPSIS
  5. .ta \w'\fLchar* 'u
  6. .B
  7. void kproc(char *name, void (*func)(void*), void *arg)
  8. .PP
  9. .B
  10. void pexit(char *note, int freemem)
  11. .PP
  12. .B
  13. void postnote(Proc *p, int dolock, char *n, int flag)
  14. .SH DESCRIPTION
  15. .I Kproc
  16. creates a new kernel process
  17. to run the function
  18. .IR func ,
  19. which is invoked as
  20. .BR "(*func)(arg)" .
  21. The string
  22. .I name
  23. is copied into the
  24. .B text
  25. field of the
  26. .B Proc
  27. structure of the new process; this value is the name of the kproc in
  28. the output of
  29. .IR ps (1).
  30. The process is made runnable; it
  31. will run when selected by the scheduler
  32. .IR sched (9).
  33. The process is created with base and current priorities set to
  34. .BR PriKproc .
  35. It shares the kernel process group and thus name space.
  36. .PP
  37. A kernel process terminates only when it calls
  38. .IR pexit ,
  39. thereby terminating itself.
  40. There is no mechanism for one process to force the termination of another,
  41. although it can send a software interrupt using
  42. .IR postnote .
  43. .I Note
  44. is a null string on normal termination, or
  45. the cause of
  46. If
  47. .I freemem
  48. is non-zero,
  49. any memory allocated by the process is discarded;
  50. it should normally be non-zero for any process created
  51. by
  52. .IR kproc .
  53. Use the following to terminate a kernel process normally:
  54. .IP
  55. .EX
  56. pexit("", 1);
  57. .EE
  58. .PP
  59. to terminate a kernel process normally.
  60. .PP
  61. .I Postnote
  62. sends a software interrupt to process
  63. .IR p ,
  64. causing it, if necessary, to wake from
  65. .IR sleep (9)
  66. or break out of a
  67. .IR rendezvous (2),
  68. with an
  69. .IR error (9)
  70. `interrupted'.
  71. Up to
  72. .B NNOTE
  73. notes can be pending at once (currently 5);
  74. if more than that arrive, the process is forced
  75. out of
  76. .I sleep
  77. and
  78. .IR rendezvous ,
  79. but the message itself is discarded.
  80. .I Postnote
  81. returns non-zero iff the note has been
  82. delivered successfully.
  83. If
  84. .I dolock
  85. is non-zero,
  86. .I postnote
  87. synchronises delivery of the note with the debugger
  88. and other operations of
  89. .IR proc (3).
  90. .I Flag
  91. is zero, or one of the following
  92. .TP
  93. .B NDebug
  94. Print the note message on the user's standard error.
  95. Furthermore, suspend the process in a
  96. .B Broken
  97. state, preserving its memory, for later debugging.
  98. .TP
  99. .B NExit
  100. Deliver the note quietly.
  101. .TP
  102. .B NUser
  103. The note comes from another process, not the system.
  104. .PP
  105. The kernel uses
  106. .I postnote
  107. to signal processes that commit grave faults,
  108. and to implement the note and kill functions of
  109. .IR proc (3).
  110. A device driver should use
  111. .I postnote
  112. only to tell a service process,
  113. previously started by the driver using
  114. .I kproc ,
  115. that it should stop;
  116. the note will cause that process to raise an
  117. .IR error (9).
  118. For example, a process started to read packets from a network device could
  119. be stopped as follows when the interface is unbound:
  120. .IP
  121. .EX
  122. postnote(readp, 1, "unbind", 0);
  123. .EE
  124. .PP
  125. where
  126. .I readp
  127. points to the appropriate
  128. .BR Proc .
  129. The text of the message is typically irrelevant.
  130. .SH SOURCE
  131. .B /sys/src/9/port/proc.c