|
JX Application Framework
|
#include <JThisProcess.h>
Classes | |
| class | Signal |
Public Member Functions | |
| ~JThisProcess () override | |
Public Member Functions inherited from JProcess | |
| JProcess (const pid_t pid) | |
| ~JProcess () override | |
| pid_t | GetPID () const |
| JError | GetPGID (pid_t *pgid) const |
| void | Quit () |
| void | Kill () |
| void | WaitUntilFinished () |
| bool | IsFinished () const |
| bool | SuccessfulFinish () const |
| bool | GetFinishReason (JChildExitReason *reason, int *result) const |
| bool | GetReturnValue (int *result) const |
| bool | GetTermSignal (int *result) const |
| bool | GetStopSignal (int *result) const |
| JError | SendSignal (const int signal) |
| JError | SendSignalToGroup (const int signal) |
| JError | SetPriority (const int priority) |
| bool | WillDeleteWhenFinished () const |
| void | ShouldDeleteWhenFinished (const bool deleteObj=true) |
| bool | WillQuitAtExit () const |
| void | QuitAtExit (const bool quit=true) |
| bool | WillKillAtExit () const |
| void | KillAtExit (const bool kill=true) |
Public Member Functions inherited from JBroadcaster | |
| JBroadcaster () | |
| virtual | ~JBroadcaster () |
| JBroadcaster & | operator= (const JBroadcaster &source) |
| bool | HasSenders () const |
| JSize | GetSenderCount () const |
| bool | HasRecipients () const |
| JSize | GetRecipientCount () const |
| virtual JString | ToString () const |
| template<class T > | |
| void | ListenTo (const JBroadcaster *sender, const std::function< void(const T &)> &f) |
Static Public Member Functions | |
| static void | Initialize () |
| static JThisProcess * | Instance () |
| static JError | Fork (pid_t *pid) |
| static void | Exit (const int returnValue) |
| static void | Abort () |
| static bool | WillQuitAtExit (const JProcess *p) |
| static void | QuitAtExit (JProcess *p, const bool quit=true) |
| static bool | WillKillAtExit (const JProcess *p) |
| static void | KillAtExit (JProcess *p, const bool kill=true) |
| static void | Ignore (JProcess *p) |
| static bool | WillCatchSignal (const int sig) |
| static void | ShouldCatchSignal (const int sig, const bool catchIt) |
| static bool | CheckForSignals () |
| static void | ChildExecFailed () |
| static void | CheckACEReactor () |
| static jmp_buf & | GetSigintJumpBuffer () |
Static Public Member Functions inherited from JProcess | |
| static JError | Create (JProcess **process, const JString &str, const JExecuteAction toAction=kJIgnoreConnection, int *toFD=nullptr, const JExecuteAction fromAction=kJIgnoreConnection, int *fromFD=nullptr, const JExecuteAction errAction=kJIgnoreConnection, int *errFD=nullptr) |
| static JError | Create (JProcess **process, const JPtrArray< JString > &argList, const JExecuteAction toAction=kJIgnoreConnection, int *toFD=nullptr, const JExecuteAction fromAction=kJIgnoreConnection, int *fromFD=nullptr, const JExecuteAction errAction=kJIgnoreConnection, int *errFD=nullptr) |
| static JError | Create (JProcess **process, const JUtf8Byte *argv[], const JSize size, const JExecuteAction toAction=kJIgnoreConnection, int *toFD=nullptr, const JExecuteAction fromAction=kJIgnoreConnection, int *fromFD=nullptr, const JExecuteAction errAction=kJIgnoreConnection, int *errFD=nullptr) |
| static JError | Create (JProcess **process, const JString &workingDirectory, const JString &str, const JExecuteAction toAction=kJIgnoreConnection, int *toFD=nullptr, const JExecuteAction fromAction=kJIgnoreConnection, int *fromFD=nullptr, const JExecuteAction errAction=kJIgnoreConnection, int *errFD=nullptr) |
| static JError | Create (JProcess **process, const JString &workingDirectory, const JPtrArray< JString > &argList, const JExecuteAction toAction=kJIgnoreConnection, int *toFD=nullptr, const JExecuteAction fromAction=kJIgnoreConnection, int *fromFD=nullptr, const JExecuteAction errAction=kJIgnoreConnection, int *errFD=nullptr) |
| static JError | Create (JProcess **process, const JString &workingDirectory, const JUtf8Byte *argv[], const JSize size, const JExecuteAction toAction=kJIgnoreConnection, int *toFD=nullptr, const JExecuteAction fromAction=kJIgnoreConnection, int *fromFD=nullptr, const JExecuteAction errAction=kJIgnoreConnection, int *errFD=nullptr) |
| static void | CheckForFinishedChild (const bool block) |
Static Public Attributes | |
| static const JUtf8Byte * | kIllegalInstruction = "IllegalInstruction::JThisProcess" |
| static const JUtf8Byte * | kFPE = "FPE::JThisProcess" |
| static const JUtf8Byte * | kSegFault = "SegFault::JThisProcess" |
| static const JUtf8Byte * | kBrokenPipe = "BrokenPipe::JThisProcess" |
| static const JUtf8Byte * | kAbort = "Abort::JThisProcess" |
| static const JUtf8Byte * | kKeyboardInterrupt = "KeyboardInterrupt::JThisProcess" |
| static const JUtf8Byte * | kTerminate = "Terminate::JThisProcess" |
| static const JUtf8Byte * | kKeyboardQuit = "KeyboardQuit::JThisProcess" |
| static const JUtf8Byte * | kParentProcessFinished = "ParentProcessFinished::JThisProcess" |
| static const JUtf8Byte * | kChildProcessFinished = "ChildProcessFinished::JThisProcess" |
| static const JUtf8Byte * | kTTYInput = "TTYInput::JThisProcess" |
| static const JUtf8Byte * | kTTYOutput = "TTYOutput::JThisProcess" |
| static const JUtf8Byte * | kTimerFinished = "TimerFinished::JThisProcess" |
| static const JUtf8Byte * | kUserSignal1 = "UserSignal1::JThisProcess" |
| static const JUtf8Byte * | kUserSignal2 = "UserSignal2::JThisProcess" |
| static const JUtf8Byte * | kUnrecognized = "Unrecognized::JThisProcess" |
Static Public Attributes inherited from JProcess | |
| static const JUtf8Byte * | kFinished = "Finished::JProcess" |
Protected Member Functions | |
| JThisProcess () | |
| int | handle_signal (int signum, siginfo_t *, ucontext_t *) override |
Protected Member Functions inherited from JBroadcaster | |
| JBroadcaster (const JBroadcaster &source) | |
| void | ListenTo (const JBroadcaster *sender) |
| void | StopListening (const JBroadcaster *sender) |
| void | ClearWhenGoingAway (const JBroadcaster *sender, void *pointerToMember) |
| void | StopListening (const JBroadcaster *sender, const std::type_info &messageType) |
| template<class T > | |
| void | Send (JBroadcaster *recipient, const T &message) |
| template<class T > | |
| void | Broadcast (const T &message) |
| virtual void | Receive (JBroadcaster *sender, const Message &message) |
| void | SendWithFeedback (JBroadcaster *recipient, Message *message) |
| void | BroadcastWithFeedback (Message *message) |
| virtual void | ReceiveWithFeedback (JBroadcaster *sender, Message *message) |
| virtual void | ReceiveGoingAway (JBroadcaster *sender) |
Interface for the JThisProcess class
Class to represent one's own UNIX process and catch signals. This class
is designed to be a single, global object, accessible via
JThisProcess::Instance().
Event loops can call CheckForSignals() in order to convert signals into
JBroadcaster messages. The messages are broadcast in the order that
the signals were received and are caught via ReceiveWithFeedback() so
that the one who handles the signal can indicate this by calling
SetCaught() before returning.
Only the first 32 signals that are received will actually be broadcast.
This shouldn't be a problem unless the event loop is blocked and the
program relies heavily on signals, neither of which should happen in a
well-designed program, I think. Let me know if you need more.
You can change which signals are caught by calling ShouldCatchSignal().
The signals that are caught by default are:
Signal Action Description
------------------------------------------------------
SIGPIPE Broken pipe: write to pipe with no readers
(non-fatal because no control over when other end dies)
SIGTERM Q Termination signal
SIGQUIT Q Quit from keyboard
SIGINT D Interrupt from keyboard
SIGHUP Hangup detected on controlling terminal
or death of controlling process
SIGCHLD Child stopped or terminated
SIGTTIN tty input for background process
SIGTTOU tty output for background process
SIGALRM Timer signal from alarm(1)
SIGUSR1 User-defined signal 1
SIGUSR2 User-defined signal 2
A = Abort if the signal is not caught.
Q = Cause CheckForSignals() to return true,
as a suggestion to the event loop to quit,
if the signal is not caught.
D = Clean up child processes that should quit or be killed
and then die
The signals that are not caught by default are:
Signal Description Reason
------------------------------------------------------
SIGSEGV Invalid memory reference How does one recover?
SIGFPE Floating point exception How does one recover?
SIGILL Illegal Instruction How does one recover?
The signals that should never be caught are:
Signal Description Reason
------------------------------------------------------
SIGKILL Kill signal Can't be caught
SIGCONT Continue if stopped It does the right thing already
SIGSTOP Stop process Can't be caught
SIGTSTP Stop typed at tty Catching this means Ctrl-Z won't work
SIGABRT Abort signal from abort(3) assert() calls abort()
abort() generates infinite # of SIGABRT's
We provide GetSigintJumpBuffer() so SIGINT handler can longjmp() back
to JXApplication(), call CleanUpBeforeSuddenDeath(), and then exit().
|
override |
|
protected |
|
static |
Cleans up processes and calls abort().
|
static |
Bumps the ACE reactor to check sockets, signals, etc.
|
static |
Checks if we have received any signals. If so, it calls BroadcastWithFeedback(). Returns true if a signal was received that implies a request to quit.
|
static |
|
static |
Cleans up processes and calls exit().
|
static |
fork() preserves everything in the child, including child processes and JProcess objects. The child must therefore toss the quit and kill lists so other child processes of the parent are not wiped out.
If no error occurs, *pid is zero inside the child process.
|
static |
|
overrideprotected |
Sets the appropriate flags so we remember to broadcast next time CheckForSignals() is called.
|
static |
Turns off Quit and Kill at exit.
|
inlinestatic |
Call this or Instance() to install the signal handlers.
|
static |
Specify whether or not the given process should be killed when we quit.
The default is for processes to not be killed.
Specify whether or not the given process should be terminated when we quit.
The default is for processes to not be terminated.
|
static |
|
static |
Returns true if the given process will be killed when we quit.
Returns true if the given process will be terminated when we quit.
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |
|
static |