HTGS  v2.0
The Hybrid Task Graph Scheduler
TaskGraphSignalHandler.hpp
Go to the documentation of this file.
1 // NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the software in any medium, provided that you keep intact this entire notice. You may improve, modify and create derivative works of the software or any portion of the software, and you may copy and distribute such modifications or works. Modified works should carry a notice stating that you changed the software and should note the date and nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the source of the software.
2 // NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE.
3 // You are solely responsible for determining the appropriateness of using and distributing the software and you assume all risks associated with its use, including but not limited to the risks and costs of program errors, compliance with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of operation. This software is not intended to be used in any situation where a failure could cause risk of injury or damage to property. The software developed by NIST employees is not subject to copyright protection within the United States.
4 
17 #ifndef HTGS_TASKGRAPHSIGNALHANDLER_HPP
18 #define HTGS_TASKGRAPHSIGNALHANDLER_HPP
19 
21 #include <csignal>
22 #include <vector>
23 #include <cstring>
24 namespace htgs {
53  public:
54 
60  static void handleSignal(int signum = SIGTERM) {
61 #ifdef _WIN32
62  std::string signalString(std::to_string(signum));
63 #else
64  std::string signalString(strsignal(signum));
65 
66 #endif
67  if (!signalHandled) {
68 
69  signalHandled = true;
70 
71  for (size_t i = 0; i < instances.size(); i++) {
72  instances[i]->writeDotToFile(signalString + "-" + std::to_string(i) + "-graph-output.dot",
74  }
75 
76  exit(signum);
77  }
78  }
79 
84  static void registerTaskGraph(AnyTaskGraphConf *taskGraph)
85  {
86  instances.push_back(taskGraph);
87  }
88 
93  static void registerSignal(int signum = SIGTERM)
94  {
95  std::signal(signum, TaskGraphSignalHandler::handleSignal);
96  }
97 
98  private:
99  static std::vector<AnyTaskGraphConf *> instances;
100  static bool signalHandled; // !< Flag to indicate if a signal has been fired or not
101 };
102 }
103 
104 bool htgs::TaskGraphSignalHandler::signalHandled = false;
105 std::vector<htgs::AnyTaskGraphConf *> htgs::TaskGraphSignalHandler::instances;
106 
107 #endif //HTGS_TASKGRAPHSIGNALHANDLER_HPP
#define DOTGEN_FLAG_SHOW_TASK_LIVING_STATUS
Shows the number of threads that are alive running the task.
Definition: TaskGraphDotGenFlags.hpp:98
static std::vector< AnyTaskGraphConf * > instances
< The task graph instances
Definition: TaskGraphSignalHandler.hpp:99
static void registerSignal(int signum=SIGTERM)
Registers a signal for handling.
Definition: TaskGraphSignalHandler.hpp:93
Implements the base class used by the TaskGraphConf, which removes the template arguments and impleme...
static void registerTaskGraph(AnyTaskGraphConf *taskGraph)
Registers a task graph to be displayed when a signal is fired.
Definition: TaskGraphSignalHandler.hpp:84
Implements a signal handler to catch events such as termination and killing of the process...
Definition: TaskGraphSignalHandler.hpp:52
static void handleSignal(int signum=SIGTERM)
Function that handles signals.
Definition: TaskGraphSignalHandler.hpp:60
Implements the base class for the TaskGraphConf class, removing the template arguments and providing ...
Definition: AnyTaskGraphConf.hpp:66
Definition: Bookkeeper.hpp:23
#define DOTGEN_FLAG_SHOW_CONNECTOR_VERBOSE
Shows verbose information within each connector in the graph.
Definition: TaskGraphDotGenFlags.hpp:92