Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

wvsubproc.h

Go to the documentation of this file.
00001 /*
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  * 
00005  * A class for reliably starting/stopping subprocesses.
00006  *
00007  * We want to avoid calling system(), since it uses the shell (and thus has
00008  * strange parsing weirdness, environment variable changes, and so on).  Plus
00009  * calling the shell when we need to is just slow.
00010  * 
00011  * On the other hand, we want handy features like the ability to wait for our
00012  * child process to die, and the ability to kill it if it doesn't (without
00013  * having to use "killall").
00014  * 
00015  * By using setsid(), we also deal with strange situations like scripts which
00016  * launch other programs.  stop() and kill() will kill them all. (If you don't
00017  * want that, use stop_primary() and kill_primary().)
00018  */
00019 #ifndef __WVSUBPROC_H
00020 #define __WVSUBPROC_H
00021 
00022 #include "wvstringlist.h"
00023 
00024 #include <signal.h>
00025 #include <time.h>
00026 
00027 class WvSubProc
00028 {
00029 public:
00030     pid_t pid;
00031     bool running;
00032     int estatus;
00033     WvStringList env;
00034     
00035     WvSubProc();
00036 
00037     WvSubProc(const char cmd[], const char * const *argv) {
00038         startv(cmd, argv);
00039     }
00040 
00041     virtual ~WvSubProc();
00042     
00043     // launch a subprocess, which will be owned by this object.
00044     int start(const char cmd[], ...);
00045     int startv(const char cmd[], const char * const *argv);
00046     
00047     // stop (kill -TERM or -KILL as necessary) the subprocess and
00048     // all its children.
00049     void stop(time_t msec_delay);
00050     
00051     // wait for the subprocess (and all its children) to die.
00052     void wait(time_t msec_delay);
00053     
00054     // send a signal to the subprocess and all its children.
00055     void kill(int sig);
00056     
00057     // send a signal only to the main subprocess.
00058     void kill_primary(int sig);
00059     
00060     // suspend the process temporarily, or resume it.
00061     void suspend()
00062         { kill(SIGSTOP); }
00063     void resume()
00064         { kill(SIGCONT); }
00065 };
00066 
00067 DeclareWvList(WvSubProc);
00068 
00069 #endif // __WVSUBPROC_H

Generated on Fri Apr 5 15:16:53 2002 for WvStreams by doxygen1.2.15