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>
21 //#include <sys/types.h> // needed for pid_t
30 class ForkedcallsController {
32 /// Get hold of the only controller that can exist inside the process.
33 static ForkedcallsController & get();
35 /// Are there any completed child processes to be cleaned-up after?
36 bool processesCompleted() const { return current_child != -1; }
38 /** Those child processes that are found to have finished are removed
39 * from the list and their callback function is passed the final
42 void handleCompletedProcesses();
44 /// Add a new child process to the list of controlled processes.
45 void addCall(ForkedProcess const &);
47 /** Kill this process prematurely and remove it from the list.
48 * The process is killed within tolerance secs.
49 * See forkedcall.[Ch] for details.
51 void kill(pid_t, int tolerance = 5);
54 Data() : pid(0), status(0) {}
59 /** These data are used by the SIGCHLD handler to populate a list
60 * of child processes that have completed and been reaped.
61 * The associated signals are then emitted within the main LyX
64 std::vector<Data> reaped_children;
65 sig_atomic_t current_child;
68 ForkedcallsController();
69 ForkedcallsController(ForkedcallsController const &);
70 ~ForkedcallsController();
72 typedef boost::shared_ptr<ForkedProcess> ForkedProcessPtr;
73 typedef std::list<ForkedProcessPtr> ListType;
74 typedef ListType::iterator iterator;
76 iterator find_pid(pid_t);
78 /// The child processes
81 /// Used to block SIGCHLD signals.
82 sigset_t newMask, oldMask;
85 } // namespace support
88 #endif // FORKEDCONTR_H