Answers for "pipe + exec duplicate stdout linux"

0

pipe + exec duplicate stdout linux

void ejecutar(char **argv){/*Funcion que ejecuta el exec*/

		
		int pip[2];
		pid_t pid;
		pid = fork();
		//printf(stdout);
		char buf[128];

		if(pid == -1){/*ERROR AL HACER FORK*/
			perror("FALLA FORK");
			exit(EXIT_FAILURE);
		}else if(pid == 0){/*PORCESO HIJO*/
			close(pip[0]);/*cerramos la entrada*/
			write(pip[1],buf,sizeof(buf));/*escribimos por el buffer*/
			close(pip[1]);
			exit(0);
			if(execvp(argv[0],argv)){
						perror("Falla Exec");
						exit(1);
			}
		}else{/*PROCESO PADRE*/
			wait(NULL);
			close(pip[1]);/*cerramos la salida*/
			read(pip[0],buf,sizeof(buf));
			close(pip[0]);
			wait(NULL);
			//kill(ret,SIGTERM);
			
			
		}
	
	}
Posted by: Guest on June-20-2020

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language