posix/coil/Process.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
20 #ifndef COIL_PROCESS_H
21 #define COIL_PROCESS_H
22 
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <libgen.h>
26 #include <signal.h>
27 #include <sys/types.h>
28 #include <sys/stat.h>
29 #include <coil/stringutil.h>
30 
31 namespace coil
32 {
33 
41  int launch_shell(std::string command)
42  {
43  signal(SIGCHLD, SIG_IGN);
44 
45  pid_t pid;
46  if((pid = fork()) < 0 )
47  { // fork failed
48  return -1;
49  }
50 
51  if (pid == 0) // I'm child process
52  {
53  // signal(SIGCHLD, SIG_IGN);
54  // signal(SIGALRM, SIG_IGN);
55  // signal(SIGHUP , SIG_IGN);
56  // signal(SIGPIPE, SIG_IGN);
57  // signal(SIGTERM, SIG_IGN);
58  setsid();
59  // close(0);
60  // close(1);
61  // close(2);
62  // open("/dev/null", O_RDWR);
63  // dup2(0, 1);
64  // dup2(0, 2);
65  // umask(0);
66 
67  coil::vstring vstr(::coil::split(command, " "));
68  char* const * argv = ::coil::toArgv(vstr);
69 
70  execvp(vstr.front().c_str(), argv);
71 
72  return -1;
73  }
74  return 0;
75  }
76 
77  int daemon(int nochdir, int noclose)
78  {
79  return daemon(nochdir, noclose);
80  }
81 
82 
83 }; // namespace coil
84 #endif // COIL_PROCESS_H
int launch_shell(std::string command)
Launching a process.
vstring split(const std::string &input, const std::string &delimiter, bool ignore_empty)
Split string by delimiter.
Definition: stringutil.cpp:346
int daemon(int nochdir, int noclose)
std::vector< std::string > vstring
Definition: stringutil.h:37
::pid_t pid_t
Get process ID of the caller process.
Definition: ace/coil/OS.h:38
char ** toArgv(const vstring &args)
Convert the given string list into the argument list.
Definition: stringutil.cpp:573
Common Object Interface Layer.


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Feb 28 2022 23:00:44