poniedziałek, 16 września 2019

Read a file with fork and exec (g++ Linux)

#include <iostream>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
using namespace std;

class open_FILE
{
private:

char *n_File;
char run_Cat[4];
pid_t child_P;
public:
open_FILE(char *name)
{


n_File=name;

strcpy(run_Cat,"cat");
}
int child_Value()
{

      char *name_File[]={"cat",n_File,NULL};
 child_P=fork();

if(child_P!=0)
return child_P;
else
execvp(run_Cat,name_File);
}
void read_F()
{
child_Value();
}
};

int main(int argc, char **argv)
{
open_FILE OPEN("/proc/cpuinfo");
OPEN.read_F();
return 0;
}

Brak komentarzy:

Prześlij komentarz