#include <iostream>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
using namespace std;
class connect_Process
{
private:
pid_t temp_pid;
int *temp;
FILE *file_stream;
void write_Message(FILE *file_message,char *test_message)
{
fprintf(file_message,"%s\n",test_message);
fflush(file_message);
}
void read_Message(FILE *file_message)
{
char *temp;
temp=new char[1024];
while(!feof(file_message) && !ferror(file_message)
&& fgets(temp,sizeof(temp),file_message)!=NULL)
fputs(temp,stdout);
delete temp;
}
public:
connect_Process()
{
temp=new int[2];
}
void info_Process(char *path)
{
pipe(temp);
temp_pid=fork();
if(temp_pid==(pid_t)0)
{
close(temp[1]);
file_stream=fdopen(temp[0],"r");
read_Message(file_stream);
close(temp[0]);
}
else
{
close(temp[0]);
file_stream=fdopen(temp[1],"w");
write_Message(file_stream,path);
close(temp[1]);
}
}
~connect_Process()
{
delete temp;
}
};
int main(int argc, char **argv)
{
char *path=argv[0];
connect_Process c_Proc;
c_Proc.info_Process(path);
return 0;
}
Brak komentarzy:
Prześlij komentarz