Kid.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_IPC_KID_H
10 #define SQUID_IPC_KID_H
11 
12 #include "SquidString.h"
13 #include "tools.h"
14 
17 class Kid
18 {
19 public:
20 
22  enum { badFailureLimit = 4 };
23 
25  enum { fastFailureTimeLimit = 10 }; // seconds
26 
27 public:
28  Kid();
29 
30  Kid(const char *role, const int id);
31 
33  void start(pid_t cpid);
34 
36  void stop(PidStatus const exitStatus);
37 
39  bool running() const;
40 
42  bool shouldRestart() const;
43 
45  pid_t getPid() const;
46 
48  bool hopeless() const;
49 
51  void forgetFailures() { badFailures = 0; }
52 
54  time_t deathDuration() const;
55 
57  bool calledExit() const;
58 
60  int exitStatus() const;
61 
63  bool calledExit(int code) const;
64 
66  bool exitedHappy() const;
67 
69  bool signaled() const;
70 
72  int termSignal() const;
73 
75  bool signaled(int sgnl) const;
76 
78  SBuf processName() const;
79 
81  SBuf gist() const;
82 
83 private:
84  void reportStopped() const;
85 
86  // Information preserved across restarts
88  int processId = 0;
89  int badFailures = 0;
90 
91  // Information specific to a running or stopped kid
92  pid_t pid = -1;
93  time_t startTime = 0;
94  time_t stopTime = 0;
95  bool isRunning = false;
97 };
98 
99 // TODO: processes may not be kids; is there a better place to put this?
100 
102 typedef enum {
103  pkOther = 0,
105  pkWorker = 2,
106  pkDisker = 4,
107  pkHelper = 8
108 } ProcessKind;
109 
111 extern int TheProcessKind;
112 
113 #endif /* SQUID_IPC_KID_H */
114 
bool calledExit() const
returns true if the process terminated normally
Definition: Kid.cc:122
int PidStatus
Definition: tools.h:94
general-purpose helper child
Definition: Kid.h:107
void reportStopped() const
describes a recently stopped kid
Definition: Kid.cc:66
void stop(PidStatus const exitStatus)
called when kid terminates, sets exiting status
Definition: Kid.cc:47
Definition: SBuf.h:86
pid_t pid
current (for a running kid) or last (for stopped kid) PID
Definition: Kid.h:92
ProcessKind
process kinds
Definition: Kid.h:102
SBuf processRole
Definition: Kid.h:87
PidStatus status
exit status of a stopped kid
Definition: Kid.h:96
void forgetFailures()
forgets all past failures, ensuring that we are not hopeless()
Definition: Kid.h:51
bool hopeless() const
whether the failures are "repeated and frequent"
Definition: Kid.cc:116
int termSignal() const
returns the number of the signal that caused the kid to terminate
Definition: Kid.cc:152
pid_t getPid() const
returns current pid for a running kid and last pid for a stopped kid
Definition: Kid.cc:109
void start(pid_t cpid)
called when this kid got started, records PID
Definition: Kid.cc:34
manages all other kids
Definition: Kid.h:104
general-purpose worker bee
Definition: Kid.h:105
bool running() const
returns true if tracking of kid is stopped
Definition: Kid.cc:91
unsigned char code
Definition: html_quote.c:20
time_t deathDuration() const
Definition: Kid.cc:180
we do not know or do not care
Definition: Kid.h:103
bool shouldRestart() const
returns true if master should restart this kid
Definition: Kid.cc:97
SBuf processName() const
returns kid name
Definition: Kid.cc:164
Definition: Kid.h:17
Kid()
Definition: Kid.cc:23
SBuf gist() const
Definition: Kid.cc:172
int TheProcessKind
ProcessKind for the current process.
Definition: Kid.cc:21
bool isRunning
whether the kid is assumed to be alive
Definition: Kid.h:95
bool signaled() const
returns true if the kid was terminated by a signal
Definition: Kid.cc:146
bool exitedHappy() const
whether the process exited with code 0
Definition: Kid.cc:140
time_t startTime
last start time
Definition: Kid.h:93
time_t stopTime
last termination time
Definition: Kid.h:94
int badFailures
number of "repeated frequent" failures
Definition: Kid.h:89
cache_dir manager
Definition: Kid.h:106
int processId
Definition: Kid.h:88
int exitStatus() const
returns the exit status of the process
Definition: Kid.cc:128

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors