MistServer  2.5.3-Pro-19-gf5e75b1 ( Generic_64)
procs.h
Go to the documentation of this file.
1 
4 #pragma once
5 #include <unistd.h>
6 #include <string>
7 #include <set>
8 #include <vector>
9 #include <deque>
10 
12 namespace Util {
13 
15  class Procs {
16  private:
17  static std::set<pid_t> plist;
18  static bool handler_set;
19  static void childsig_handler(int signum);
20  static void exit_handler();
21  static void runCmd(std::string & cmd);
22  static void setHandler();
23  static char* const* dequeToArgv(std::deque<std::string> & argDeq);
24  public:
25  static std::string getOutputOf(char * const * argv);
26  static std::string getOutputOf(std::deque<std::string> & argDeq);
27  static pid_t StartPiped(char * const * argv, int * fdin, int * fdout, int * fderr);
28  static pid_t StartPiped(std::deque<std::string> & argDeq, int * fdin, int * fdout, int * fderr);
29  static void Stop(pid_t name);
30  static void Murder(pid_t name);
31  static void StopAll();
32  static int Count();
33  static bool isActive(pid_t name);
34  static bool isRunning(pid_t pid);
35  };
36 
37 }
static bool isActive(pid_t name)
Returns true if a process with this PID is currently active.
Definition: procs.cpp:395
static void childsig_handler(int signum)
Used internally to capture child signals and update plist.
Definition: procs.cpp:149
static void Murder(pid_t name)
Stops the process with this pid, if running.
Definition: procs.cpp:376
static void exit_handler()
Called at exit of any program that used a Start* function.
Definition: procs.cpp:49
static void setHandler()
Sets up exit and childsig handlers.
Definition: procs.cpp:135
static char *const * dequeToArgv(std::deque< std::string > &argDeq)
This function prepares a deque for getOutputOf and automatically inserts a NULL at the end of the cha...
Definition: procs.cpp:206
static bool handler_set
If true, the sigchld handler has been setup.
Definition: procs.h:18
Contains utility code, not directly related to streaming media.
Definition: bitfields.h:3
static void runCmd(std::string &cmd)
static void Stop(pid_t name)
Stops the process with this pid, if running.
Definition: procs.cpp:370
static pid_t StartPiped(char *const *argv, int *fdin, int *fdout, int *fderr)
Starts a new process with given fds if the name is not already active.
Definition: procs.cpp:235
static std::string getOutputOf(char *const *argv)
Runs the given command and returns the stdout output as a string.
Definition: procs.cpp:186
static void StopAll()
(Attempts to) stop all running child processes.
Definition: procs.cpp:381
static std::set< pid_t > plist
Holds active processes.
Definition: procs.h:17
static bool isRunning(pid_t pid)
sends sig 0 to process (pid). returns true if process is running
Definition: procs.cpp:41
Deals with spawning, monitoring and stopping child processes.
Definition: procs.h:15
static int Count()
Returns the number of active child processes.
Definition: procs.cpp:390