ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/host/c++/socket++-1.10/Fork.h
Revision: 1.1
Committed: Mon Feb 26 15:01:39 2001 UTC (23 years, 8 months ago) by ab11
Content type: text/plain
Branch: MAIN
CVS Tags: PROJECT_COMPLETION
Log Message:
Networking class. Assumed to be bug free.

File Contents

# User Rev Content
1 ab11 1.1 // Fork.h -*- C++ -*- socket library
2     // Copyright (C) 1992,1993,1994 Gnanasekaran Swaminathan <gs4t@virginia.edu>
3     //
4     // Permission is granted to use at your own risk and distribute this software
5     // in source and binary forms provided the above copyright
6     // notice and this paragraph are preserved on all copies.
7     // This software is provided "as is" with no express or implied warranty.
8     //
9     // Version: 17Oct95 1.10
10    
11     #ifndef FORK_H
12     #define FORK_H
13    
14     #include <unistd.h>
15     #include <sys/types.h>
16     #include <sys/signal.h>
17    
18     class Fork {
19     public:
20     class KillForks {
21     public:
22     KillForks () {}
23     ~KillForks ();
24     };
25    
26     class ForkProcess {
27     friend Fork::KillForks::~KillForks ();
28    
29     static void infanticide_reason (pid_t pid, int status);
30     static void reaper_nohang (int);
31    
32     static ForkProcess* list;
33     public:
34     pid_t pid;
35     const char kill_child;
36     const char reason;
37     ForkProcess* next;
38    
39     ForkProcess (int kill, int give_reason);
40     ~ForkProcess ();
41    
42     void kill_process () const;
43     void reap_child () const;
44    
45     static void commit_suicide (int);
46     };
47     private:
48     static KillForks killall;
49    
50     ForkProcess* process;
51    
52     Fork (Fork&); // no copy constructor definition provided
53     Fork& operator = (Fork&); // no assignment operator definition provided
54     public:
55     Fork (int kill = 0, int reason = 0)
56     : process (new ForkProcess (!!kill, !!reason)) {}
57     ~Fork ();
58    
59     int is_child () const { return process->pid == 0; }
60     int is_parent () const { return process->pid > 0; }
61     int process_id () const { return process->pid; }
62    
63     static void suicide_signal (int signo = SIGTERM);
64     };
65    
66     #endif // FORK_H