man(1) Manual page archive


     KPROC(9)                                                 KPROC(9)

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

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

          void  pexit(char *note, int freemem)

          void  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), with an error(9) `interrupted'.  Up to NNOTE
          notes can be pending at once (currently 5); if more than
          that arrive, the process is forced out of sleep and
          rendezvous, but the message itself is discarded.  Postnote
          returns non-zero iff the note has been delivered success-
          fully.  If dolock is non-zero, postnote synchronises deliv-
          ery 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,
               preserving its memory, for later debugging.

     KPROC(9)                                                 KPROC(9)

          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