Belle II Software  release-08-01-10
RFProcessManager Class Reference
Collaboration diagram for RFProcessManager:

Public Member Functions

 RFProcessManager (char *nodename)
 
int Execute (char *script, int nargs, char **args)
 
int Execute (char *scr, char *arg0=NULL, char *arg1=NULL, char *arg2=NULL, char *arg3=NULL, char *arg4=NULL, char *arg5=NULL, char *arg6=NULL, char *arg7=NULL)
 
int CheckOutput ()
 
int GetFd ()
 
pid_t CheckProcess ()
 

Static Public Member Functions

static void signal_handler (int num)
 

Private Attributes

int m_iopipe [2]
 
int m_fdout
 
std::vector< pid_t > m_pidlist
 

Detailed Description

Definition at line 22 of file RFProcessManager.h.

Member Function Documentation

◆ Execute()

int Execute ( char *  script,
int  nargs,
char **  args 
)

Fill arg0

Definition at line 55 of file RFProcessManager.cc.

56 {
57 
58  printf("RFProcessManager : Execute : scr=%s, nargs=%d\n", scr, nargs);
59  // Fork processes
60  pid_t pid = fork();
61  if (pid == (pid_t) 0) { // In case of forked process
62  char argbuf[10][256];
63  char* argval[10];
64  int nargval = 0;
66  strcpy(argbuf[0], scr);
67  argval[nargval++] = argbuf[0];
68  // Fill argbuf
69  for (int i = 0; i < nargs; i++) {
70  strcpy(argbuf[nargval], args[i]);
71  argval[nargval] = argbuf[nargval];
72  nargval++;
73  // printf ( "argval[%d] = %s\n", i+1, argval[i+1] );
74  }
75  argval[nargval] = NULL;
76 
77  // Connect stderr/out to write pipe[1], which is read by parent process thru pipe[0]
78  close(1);
79  dup2(m_iopipe[1], 1); // redirect stderr to pipe 1
80  close(2);
81  dup2(m_iopipe[1], 2); // redirect stdout to pipe 1
82  close(m_iopipe[0]); // Close read pipe in child process
83 
84  // execute script in forked process by execvp()
85  printf("RFProcessManager : invoking %s\n", scr);
86  for (int i = 0; i < 10; i++) {
87  if (argval[i] == NULL) break;
88  printf("argval[%d] = %s\n", i, argval[i]);
89  }
90  fflush(stdout);
91  fflush(stderr);
92  execvp(scr, argval); // returns int stexe
93  perror("execvp!!");
94  fprintf(stderr, "missing file : %s\n", scr);
95  fflush(stderr);
96  exit(-1);
97  }
98  // Parent process (pid>0 : success, pid<0 : error )
99  printf("RFProcessManager : forked. pid=%d\n", pid);
100  //close(m_iopipe[1]);
101 
102  m_pidlist.push_back(pid);
103  return pid;
104 }

The documentation for this class was generated from the following files: