4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Asger Alstrup Nielsen
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
12 * A class for the control of child processes launched using
13 * fork() and execvp().
19 #include <boost/shared_ptr.hpp>
22 //#include <sys/types.h> // needed for pid_t
31 class ForkedcallsController {
33 /// Get hold of the only controller that can exist inside the process.
34 static ForkedcallsController & get();
36 /// Are there any completed child processes to be cleaned-up after?
37 bool processesCompleted() const { return current_child != -1; }
39 /** Those child processes that are found to have finished are removed
40 * from the list and their callback function is passed the final
43 void handleCompletedProcesses();
45 /// Add a new child process to the list of controlled processes.
46 void addCall(ForkedProcess const &);
48 /** Kill this process prematurely and remove it from the list.
49 * The process is killed within tolerance secs.
50 * See forkedcall.[Ch] for details.
52 void kill(pid_t, int tolerance = 5);
55 Data() : pid(0), status(0) {}
60 /** These data are used by the SIGCHLD handler to populate a list
61 * of child processes that have completed and been reaped.
62 * The associated signals are then emitted within the main LyX
65 std::vector<Data> reaped_children;
66 sig_atomic_t current_child;
69 ForkedcallsController();
70 ForkedcallsController(ForkedcallsController const &);
71 ~ForkedcallsController();
73 typedef boost::shared_ptr<ForkedProcess> ForkedProcessPtr;
74 typedef std::list<ForkedProcessPtr> ListType;
75 typedef ListType::iterator iterator;
77 iterator find_pid(pid_t);
79 /// The child processes
82 /// Used to block SIGCHLD signals.
83 sigset_t newMask, oldMask;
86 } // namespace support
89 #endif // FORKEDCONTR_H