2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 * A class for reliably starting/stopping subprocesses.
7 * We want to avoid calling system(), since it uses the shell (and
8 * thus has strange parsing weirdness, environment variable changes,
9 * and so on). Plus calling the shell when we need to is just slow.
11 * On the other hand, we want handy features like the ability to wait
12 * for our child process to die, and the ability to kill it if it
13 * doesn't (without having to use "killall").
15 * By using setsid(), we also deal with strange situations like
16 * scripts which launch other programs. stop() and kill() will kill
17 * them all. (If you don't want that, use stop_primary() and
23 #include "wvstringlist.h"
38 WvString pidfile
, last_cmd
, app
;
39 WvStringList last_args
, env
;
44 WvSubProc(const char cmd
[], const char * const *argv
)
45 { init(); startv(cmd
, argv
); }
51 int _startv(const char cmd
[], const char * const *argv
);
56 void prepare(const char cmd
[], ...);
57 void preparev(const char cmd
[], va_list ap
);
58 void preparev(const char cmd
[], const char * const *argv
);
59 void preparev(const char cmd
[], WvStringList
&);
61 // launch a subprocess, which will be owned by this object.
62 int start(const char cmd
[], ...);
64 int startv(const char cmd
[], const char * const *argv
);
65 virtual int start_again();
67 virtual int fork(int *waitfd
);
69 // stop (kill -TERM or -KILL as necessary) the subprocess and
71 virtual void stop(time_t msec_delay
, bool kill_children
= true);
73 // wait for the subprocess (and all its children) to die.
74 virtual void wait(time_t msec_delay
, bool wait_children
= true);
76 // figure out the pid from the /var/run pidfile
79 /// Sets a limit on the number of megabytes of memory the subprocess will
81 void setMemLimit(int megs
) { memlimit
= megs
; }
83 // send a signal to the subprocess and all its children.
86 // send a signal only to the main subprocess.
87 void kill_primary(int sig
);
89 // suspend the process temporarily, or resume it.
90 virtual void suspend()
96 DeclareWvList(WvSubProc
);
98 #endif // __WVSUBPROC_H