c - problem with fork() -


I am writing a shell that parses the input and parsing process to read the parent and executes with execvp.

The main method's pseudocode:

  do {pid = fork ()); Print pid; If (P & lt; 0) {error; Go out; } If (P & gt; 0) {wait for the child to finish; Read input; } And {call function to parse the input function; Go out; }} While returning status;  

What happens is that I do not ever feel like entering the hair process (printing pad is always positive, I do not ever enter it). However, if I do not call the parse function and just exit, then I optionally enter the parent and child.

  Full code: int main (int argc, char * argv []) {four input [500]; Pid_t p; Int firstrun = 1; Do {p = fork (); Printf ("PID:% d", p); If (p & l; 0) {printf ("faulting error"); Exit (-1);} If (P & gt; 0) {Wait (zero); Firstrun = 0; Printf ("\ n";); Berboo (input, 500); Fflush (stdout); Read (0, Input, 499); Input [Stellen (input) -1] = '\ 0'; } And exit (0); And (if (pars (input)! = 0 & amp; amp; firstrun! = 1) {printf ("error parsing"); exit (-1);} exit (0);}} while (Strcmp (input, "exit")! = 0); return 0;}  

edit:

And exit (0) just something that I forgot to play around

By adding a new line for the print, it shows that it actually works correctly and the hair process Enters; Thank you, the problem looks in pars.

one criminal else exit (0));

This child will be executed in the shell, which means that it never reaches the parsing phase. The code also syntax is invalid because after that your other others


Comments