linux - C++ fork() and execv() problems -


I'm a type of novice on C ++, and I'm working on a simple program on Linux, Invite the program to get the output of the program delivered without showing the output of the program applied to the directory and the console. This is the code snippet on which I am working:

  pid_t pid; Cout & lt; & Lt; "General message:" & lt; Andal & lt; & Lt; Sentence & lt; & Lt; Endl; The court's & lt; & Lt; "===============================" & lt; & Lt; Endl; // int i = system ("./satzoo"); If (pid = fork () & lt; 0) cout & lt; & Lt; "The process could not be created ..." & lt; & Lt; Endl; Else {cout & lt; & Lt; Pid & lt; & Lt; Endl; Execv ("./ Satzoo", zero); } COAT & LT; & Lt; "General Sentence:" & lt; And L & LT; & Lt; Sentence & Lt; & Lt; Andal; The court's & lt; & Lt; "===============================" & lt; & Lt; Endl;  

The problem I am facing is that I am able to print the first two rows on the console, but I can not print the last two lines I think the program will work Stop when I invoke the Tsatuzu program. Another thing is that this code invites the Sezza Program twice, I do not know why? I can see the output twice on screen. On the other hand if I use system () instead of execv (), then SATZU works only once.

I do not know how to read Satu's production in my program.

Any help is appreciated.

Thank you

You are not fork () Diving to the middle of the process of child and parent after call for Therefore both children and parents run execv () and thus their related process images are changed.

You want something more like:

  Pid_t pid; Printf ("before fork \ n"); If ((pid = fork ()) & lt; 0) {printf ("There was an error during the rounding \ n"); } Else if (pid == 0) {/ * this child is * / printf ("baby pip is:% d \ n", getpid ()); Execv ("./ Satzoo", zero); Printf ("If this line is printed then execv fails \ n"); } Other {/ * This is parent * / printf ("Parents continuous execution \ n"); }  

Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -