diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1999-08-30 21:26:48 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1999-08-30 21:26:48 +0000 |
commit | 82455c2029d9946c5ccfa12a1c3a38d3d15270e5 (patch) | |
tree | 263e2600bcc0702ebce60fcf5e53bdb630803b28 /ace/Process_Manager.h | |
parent | 2df08d0bea3dda3312f99cf54ae31e138d97565e (diff) | |
download | ATCD-82455c2029d9946c5ccfa12a1c3a38d3d15270e5.tar.gz |
ChangeLogTag:Mon Aug 30 16:12:36 1999 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu>
Diffstat (limited to 'ace/Process_Manager.h')
-rw-r--r-- | ace/Process_Manager.h | 139 |
1 files changed, 107 insertions, 32 deletions
diff --git a/ace/Process_Manager.h b/ace/Process_Manager.h index b852ff4a5ec..8f970cebe5b 100644 --- a/ace/Process_Manager.h +++ b/ace/Process_Manager.h @@ -18,6 +18,8 @@ #define ACE_PROCESS_MANAGER_H #include "ace/Synch.h" +#include "ace/Reactor.h" +#include "ace/Event_Handler.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once @@ -28,7 +30,7 @@ class ACE_Export ACE_Process_Descriptor { // = TITLE - // Information describing each process that's controlled by the + // Information describing each process that's controlled by an // <ACE_Process_Manager>. private: friend class ACE_Process_Manager; @@ -37,17 +39,20 @@ private: ~ACE_Process_Descriptor (void); // Default ctor/dtor. - pid_t proc_id_; - // Unique process ID. + int delete_process_; + // Do we need to delete the Process, or just close() it? - gid_t grp_id_; - // Unique group ID. + ACE_Process *process_; + // Describes the process itself. + + ACE_Event_Handler *exit_notify_; + // function to call when process exits void dump (void) const; // Dump the state of an object. }; -class ACE_Export ACE_Process_Manager +class ACE_Export ACE_Process_Manager : protected ACE_Event_Handler { // = TITLE // Manages a group of processes. @@ -74,9 +79,32 @@ public: }; // = Initialization and termination methods. - ACE_Process_Manager (size_t size = ACE_Process_Manager::DEFAULT_SIZE); + ACE_Process_Manager (size_t size = ACE_Process_Manager::DEFAULT_SIZE, + ACE_Reactor *reactor = 0); + // Initialize an <ACE_Process_Manager> with a table containing up to + // <size> processes. This table resizes itself automatically as + // needed. If a non-NULL <reactor> is provided, this + // <ACE_Process_Manager> uses it to notify an application when a + // process it controls exits. By default, however, we don't use an + // <ACE_Reactor>. + + int open (size_t size = DEFAULT_SIZE, + ACE_Reactor *r = ACE_Reactor::instance ()); + // Initialize an <ACE_Process_Manager> with a table containing up to + // <size> processes. This table resizes itself automatically as + // needed. If a non-NULL <reactor> is provided, this + // <ACE_Process_Manager> uses it to notify an application when a + // process it controls exits. By default, however, we don't use an + // <ACE_Reactor>. + + int close (void); + // Release all resources. Do not wait for processes to exit. + virtual ~ACE_Process_Manager (void); + // Destructor releases all resources and does not wait for processes + // to exit. + // = Singleton accessors. static ACE_Process_Manager *instance (void); // Get pointer to a process-wide <ACE_Process_Manager>. @@ -84,13 +112,13 @@ public: // Set pointer to a process-wide <ACE_Process_Manager> and return // existing pointer. - int open (size_t size = DEFAULT_SIZE); - // Initialize an <ACE_Process_Manager> with a table containing up to - // <size> processes. This table resizes itself automatically as - // needed. + // = Process creation methods. - int close (void); - // Release all resources. + pid_t spawn (ACE_Process *proc, + ACE_Process_Options &options); + // Create a new process by passing <options> to <proc.spawn>. On + // success, returns the process id of the child that was created. + // On failure, returns -1. pid_t spawn (ACE_Process_Options &options); // Create a new process by passing <options> to @@ -106,6 +134,8 @@ public: // are filled in with the process ids of each newly created process. // Returns 0 on success and -1 on failure. + // = Process synchronization operations. + int wait (void); // Block until there are no more child processes running that were // <spawn>ed by this <ACE_Process_Manager>. Unlike the <wait> call @@ -113,23 +143,24 @@ public: // <ACE_OS::sigwait> because it simply blocks synchronously waiting // for all the children managed by this <ACE_Process_Manager> to // exit. Note that this does not return any status information - // about the success or failure of exiting child processes. Returns + // about the success or failure of exiting child processes, although + // any registered exit_handlers are called. Returns // 0 on success (and <remove>s the corresponding - // <ACE_Process_Descriptor> entry from the <Process_Manager>; + // <ACE_Process_Descriptor> entries from the <Process_Manager>; // otherwise, returns -1 on failure. int wait (ACE_Time_Value *timeout); // Block until there are no more child processes running that were - // <spawn>ed by this <ACE_Process_Manager> or <timeout> expires. In - // order for this <wait> method to work you'll need to register a - // signal handler or use <ACE_OS::sigwait> to call the <reap> or - // <remove> method when a <SIGCHILD> signal occurs. Therefore, this - // method is not portable to Win32... Returns 0 on success and -1 - // on failure. - - int wait (pid_t pid, - int *stat_loc, - int options); + // <spawn>ed by this <ACE_Process_Manager> or <timeout> expires. + // Returns 0 on success and -1 on failure. + + int wait (pid_t pid, ACE_Time_Value *timeout); + // Block until pid exits or <timeout> expires. + // Returns 0 on success and -1 on failure. + + int wait (pid_t pid = -(ACE_OS::getpid( )), + int *stat_loc = 0, + int options = WNOHANG ); // Reap the result of a single process by calling <ACE_OS::wait>. // If the child is successfully reaped, <remove> is called // automatically. Note that this method can be portably called @@ -148,6 +179,13 @@ public: // method does the same thing that the <wait> method directly above // it does -- It's just here for backwards compatibility. + // = Utility methods. + int register_handler (ACE_Event_Handler *event_handler, + pid_t pid = ACE_INVALID_PID); + // Register an Event_Handler to be called back when the specified + // process exits. If pid == ACE_INVALID_PID this handler is called + // when any process with no specific handler exits. + int remove (pid_t pid); // Remove process <pid> from the table. This is called // automatically by the <reap> method after it successfully reaped a @@ -162,26 +200,51 @@ public: // may not have a chance to cleanup before it shuts down. Returns 0 // on success and -1 on failure. + int terminate (pid_t pid, int sig); + // On OSs that support signals, send the signal to the specified + // process. Returns 0 on success and -1 on failure. + void dump (void) const; // Dump the state of an object. ACE_ALLOC_HOOK_DECLARE; // Declare the dynamic allocation hooks. +protected: + // = These methods allow a <Process_Manager> to be an <Event_Handler>. + + // @@ Dave, can you please add comments for these methods. + virtual ACE_HANDLE get_handle (void) const; + // Return the handle. + + virtual int handle_input (ACE_HANDLE); + // + virtual int handle_signal (int signum, siginfo_t * = 0, + ucontext_t * = 0); + // + virtual int handle_close (ACE_HANDLE handle, + ACE_Reactor_Mask close_mask); + // + private: int resize (size_t); // Resize the pool of Process_Descriptors. int find_proc (pid_t process_id); // Locate the index of the table slot occupied by <process_id>. - // Returns -1 if <process_id> is not in the <process_table_> doesn't - // contain <process_id>. + // Returns -1 if <process_id> is not in the <process_table_> + +#if defined (ACE_WIN32) + int find_proc (ACE_HANDLE process_handle); + // Locate the index of the table slot occupied by <process_handle>. + // Returns -1 if <process_handle> is not in the <process_table_> +#endif /* ACE_WIN32 */ - int insert_proc (pid_t process_id); - // Insert a process in the table (checks for duplicates). - // Omitting the process handle won't work on Win32... + int insert_proc (ACE_Process *process); + // Insert a process in the table (checks for duplicates). Omitting + // the process handle won't work on Win32... - int append_proc (pid_t process_id); + int append_proc (ACE_Process *process); // Append information about a process, i.e., its <process_id> in the // <process_table_>. Each entry is added at the end, growing the // table if necessary. @@ -190,6 +253,12 @@ private: // Actually removes the process <pid> from the table. This method // must be called with locks held. + int notify_proc_handler (ACE_HANDLE proc, + pid_t pid, + int status); + // If there's a specific handler for <pid>'s exit, or a default + // handler, call it. + ACE_Process_Descriptor *process_table_; // Vector that describes process state within the Process_Manager. @@ -200,6 +269,13 @@ private: size_t current_count_; // Current number of processes we are managing. + ACE_HANDLE dummy_handle_; + // Allows SIGCHLD to be handled synchronously. + + ACE_Event_Handler *default_exit_handler_; + // This event handler is used to notify when a process we control + // exits. + static ACE_Process_Manager *instance_; // Singleton pointer. @@ -219,4 +295,3 @@ private: #endif /* __ACE_INLINE__ */ #endif /* ACE_PROCESS_MANAGER_H */ - |