Using pipe for IPC
===

I'm currently studying IPC, I have a first program 

A: Do an exec for B and wait 

B: Receive through a fifo a string from a third program "C" and have to resend it to A

I was thinking to open a pipe in A before the exec, then passing fd[1] to B as an argument
 

	if(pipe(fd)==-1){
		perror("Pipe Failed");
		myExit(EXIT_FAILURE);
	}

	close(fd[1]);	
	sprintf(fdString,"%d",fd[1]);

        .......

	if((int)(pid=fork())>0)
		
		waiting(status);	
	
	else if(pid==0){	
		
		close(fd[0]);	

		execl("./B","B",fdString,(char*)0);
		perror("Exec failed");
		myExit(EXIT_FAILURE);

	}


Then in B:

	int fd=atoi(argv[1]);
        
        //Receive string from C 

       	len=strlen(string)+1;

	if(write(fd,&len,sizeof(int))==-1){
		perror("Error on writing length");
		exit(EXIT_FAILURE);	
	}

	if(write(fd,&string,len)==-1){
		perror("Error on writing string");
		exit(EXIT_FAILURE);		
	}


My problem now is reading this string in A. I was thinking something to send a SIGUSR1 to A as soon as the string is written by B on the pipe and having in A something like:

	signal(SIGUSR1, signalHandler);
        ........
      	static void signalHandler(int signo){
		switch(signo){
		case SIGUSR1:
			listen();
			break;
		default: break;

		}
	}
        ........
	static void listen(){
	
		int len;
	
		if(read(fd[0],&len,sizeof(int))<sizeof(int)){
			perror("Error reading len");
			myExit(EXIT_FAILURE);	
		}
	
		char string[len];
	
		if(read(fd[0],string,len)<len){
			perror("Error reading string");
			myExit(EXIT_FAILURE);	
		}
		printf("String: %s with length %d\n", string, len);
	}



However what I get is  *"Error reading len: Success"* , what's wrong ? 

Sorry if my English is bad, any help is appreciated, thanks!


