c - Passing a pipe address through argv -


i'm trying set program 1 process establishes pipe, passed children either reading or writing. tried using argv parameter communicate address of pipe children use, i'm doing wrong , keep getting segmentation fault when try run it

parent:

void main(int argc, char *argv [ ]){ int temp,b,c,d,num; char *arg[1]={0};  int fd[2]; pipe(fd); b=1; c=1; d=1; sprintf(arg[0], "%d", fd);  b=fork(); if (b==0){execv("pipew1", arg);}  c=fork(); if (c==0){execv("pipew2", arg);}  d=fork(); if (d==0){execv("piper", arg);} 

children

void main(int argc, char *argv [ ]){ int *fd = atoi(argv[0]); //pipe(fd); close(fd[1]); 

well one, argv[0] name of executable, first "real" argument in argv[1]. might idea check if have appropriate number of arguments before accessing them in argv array.
another thing in child process should initialize fd int not pointer int.
third problem might in close(fd[1]) treating fd array when in fact scalar integer value.
problems in child proccess...


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -