KPROC(9)                                                 KPROC(9)

     NAME
          kproc, pexit, postnote - kernel process creation,
          termination and interruption

     SYNOPSIS
          void kproc(char *name, void (*func)(void*), void *arg)

          void pexit(char *note, int freemem)

          int  postnote(Proc *p, int dolock, char *n, int flag)

     DESCRIPTION
          Kproc creates a new kernel process to run the function func,
          which is invoked as (*func)(arg).  The string name is copied
          into the text field of the Proc structure of the new pro-
          cess; this value is the name of the kproc in the output of
          ps(1). The process is made runnable; it will run when
          selected by the scheduler sched(9). The process is created
          with base and current priorities set to PriKproc.  It shares
          the kernel process group and thus name space.

          A kernel process terminates only when it calls pexit,
          thereby terminating itself.  There is no mechanism for one
          process to force the termination of another, although it can
          send a software interrupt using postnote. Note is a null
          string on normal termination, or the cause of If freemem is
          non-zero, any memory allocated by the process is discarded;
          it should normally be non-zero for any process created by
          kproc. Use the following to terminate a kernel process nor-
          mally:

               pexit("", 1);

          to terminate a kernel process normally.

          Postnote sends a software interrupt to process p, causing
          it, if necessary, to wake from sleep(9) or break out of a
          rendezvous(2) or an eqlock(9), with an error(9) `inter-
          rupted'.  Up to NNOTE notes can be pending at once (cur-
          rently 5); if more than that arrive, the process is forced
          out of sleep, rendezvous and eqlock, but the message itself
          is discarded.  Postnote returns non-zero iff the note has
          been delivered successfully.  If dolock is non-zero,
          postnote synchronises delivery of the note with the debugger
          and other operations of proc(3). Flag is zero, or one of the
          following

          NDebug
               Print the note message on the user's standard error.
               Furthermore, suspend the process in a Broken state,

     Page 1                       Plan 9              (printed 4/8/20)

     KPROC(9)                                                 KPROC(9)

               preserving its memory, for later debugging.

          NExit
               Deliver the note quietly.

          NUser
               The note comes from another process, not the system.

          The kernel uses postnote to signal processes that commit
          grave faults, and to implement the note and kill functions
          of proc(3). A device driver should use postnote only to tell
          a service process, previously started by the driver using
          kproc , that it should stop; the note will cause that pro-
          cess to raise an error(9). For example, a process started to
          read packets from a network device could be stopped as fol-
          lows when the interface is unbound:

               postnote(readp, 1, "unbind", 0);

          where readp points to the appropriate Proc.  The text of the
          message is typically irrelevant.

     SOURCE
          /sys/src/9/port/proc.c

     Page 2                       Plan 9              (printed 4/8/20)