home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lyx-0.13.2.tar.gz / lyx-0.13.2.tar / lyx-0.13.2 / src / procMgr.C < prev    next >
C/C++ Source or Header  |  1998-04-23  |  2KB  |  79 lines

  1. // Intended to be a process manager, keep controll over which processes
  2. // has been started in a non-blocking manner (fork, exec)
  3. // and what to do when they return.
  4.  
  5. /*
  6.   This is kindo how I'd like this to work:
  7.  
  8.   The class have controll of all the pids we are currently waiting for
  9.   what to do when we gets it.
  10.  
  11.   The class will also know if the pid returned from wait is expected or not.
  12.  
  13.   This could be the interface to the class:
  14.   
  15.   pid_connect(pid, <func>);
  16.  
  17.   connects a pid to a function that should be run when that process returns.
  18.  
  19.   will this always be able to get the pid? Or might this turn zombies on us?
  20.  
  21.   */
  22.  
  23. #include <config.h>
  24. #include <stdio.h>
  25. #include "procMgr.h"
  26. #include "error.h"
  27.  
  28. // from spellchecker.C
  29. extern void sigchldhandler(int sig);
  30.  
  31. ProcessManager procMgr;
  32.  
  33.  
  34. void ProcessManager::procMgr_sa_handler(int) {
  35.     procMgr.handleChildDeath();
  36. }
  37.  
  38.  
  39. ProcessManager::ProcessManager() {
  40.     pw = NULL;
  41.     // This is what I want:
  42.     //act.sa_handler = procMgr_sa_handler;
  43.     // this is what I use for now:
  44.     act.sa_handler = sigchldhandler;
  45.     //act.sa_mask = 0;
  46.     act.sa_flags = 0;
  47.     sigaction(SIGCHLD, &act, NULL);
  48. };
  49.  
  50.  
  51. void ProcessManager::handleChildDeath()
  52. {
  53.     lyxerr.print("Child sig caught!");
  54. }
  55.  
  56.  
  57.  
  58. void ProcessManager::addpidwait(int pid)
  59. {
  60.     // adds pid to pid wait list
  61.     register pidwait *p = new pidwait;
  62.  
  63.     p->pid = pid;
  64.     p->next = pw;
  65.     pw = p;
  66.  
  67.     if (lyxerr.debugging()) {
  68.         lyxerr.print(LString("Pids to wait for: \n")+ int(p->pid));
  69.         while (p->next) {
  70.             p = p->next;
  71.             lyxerr.print(LString("") + int(p->pid));
  72.         }
  73.     }
  74. }
  75.  
  76.  
  77.  
  78.  
  79.