This is a problem with using vfork in my simple program. After i run my
program and tell it to execlp a command it does it but most off the time i
get a race condition, and always execlp executes on both child and on the
parent.
help please.
my simple program is the attachmnt
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#define MAX_COMMAND 162
int main(void){
int exit_code;
pid_t running_ps,shell_ps;
char command_line[MAX_COMMAND];
printf("--->");
while(fgets(command_line,MAX_COMMAND,stdin)!=NULL){
command_line[strlen(command_line)-1]=0;
if(running_ps=vfork()<0){
printf("Cant vfork a ps\n");
}else if(running_ps == 0){
execlp(command_line,command_line,(char *) 0);
}
if(running_ps=waitpid(running_ps,&exit_code,0)<0) {
printf("cant waitpid \n");
}
printf("--->");
}
}