SigIntAnalyzer_module.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 // Class: SigIntAnalyzer
3 // Module Type: analyzer
4 // File: SigIntAnalyzer_module.cc
5 //
6 // Generated at Wed Jul 17 11:09:19 2013 by Christopher Green using artmod
7 // from cetpkgsupport v1_02_00.
8 ////////////////////////////////////////////////////////////////////////
9 
14 #include "fhiclcpp/ParameterSet.h"
15 
16 #include <signal.h>
17 #include <string>
18 #include <unistd.h>
19 
20 namespace art {
21  namespace test {
22  class SigIntAnalyzer;
23  }
24 }
25 
27 public:
28  struct Config {
30  fhicl::Name{"signal"},
31  fhicl::Comment{"Job-ending signal to be emitted. Can choose from\n"
32  "SIGUSR2, SIGTERM, SIGQUIT, or SIGINT."}};
33  };
35 
36  explicit SigIntAnalyzer(Parameters const& p);
37 
38  void analyze(Event const&) override;
39 
40 private:
41  int signal_;
42 };
43 
45 {
46  auto const signal = p().signal();
47  if (signal == "SIGUSR2") {
48  signal_ = SIGUSR2;
49  } else if (signal == "SIGTERM") {
50  signal_ = SIGTERM;
51  } else if (signal == "SIGQUIT") {
52  signal_ = SIGQUIT;
53  } else if (signal == "SIGINT") {
54  signal_ = SIGINT;
55  } else {
57  << "Incorrect signal string specified. Please select from:\n"
58  << " SIGUSR2,\n"
59  << " SIGTERM,\n"
60  << " SIGQUIT, or\n"
61  << " SIGINT.";
62  }
63 }
64 
65 void
67 {
68  kill(getpid(), signal_);
69 }
70 
Definition: test.py:1
void analyze(Event const &) override
#define DEFINE_ART_MODULE(klass)
Definition: ModuleMacros.h:68
p
Definition: test.py:228
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
SigIntAnalyzer(Parameters const &p)