본문 바로가기

42/PIPEX3

[ PIPEX / C ] 부모-자식 프로세스에서 실행할 함수 구현 우선은 부모 프로세스에서 실행할 함수이다. void change_fd_parent(t_pipex *pipex, char *argv[], char **envp) { pipex->cmd = ft_split(argv[3], ' '); close(pipex->pipefd[1]); dup2(pipex->pipefd[0], STDIN_FILENO); dup2(pipex->outfile, STDOUT_FILENO); close(pipex->outfile); close(pipex->pipefd[0]); execute_cmd(pipex, envp); free(pipex->cmd); pipex->cmd = 0; } 인자로 받은 명령어를 split으로 공백 구분 후 결과를 cmd에 저장 close를 통해 파이.. 2024. 3. 23.
[PIPEX / C] Utils & SanityCheck Funcs 구현 t_boolean check_argc(int argc) { if (argc != 5) { perror("Usage: ./pipex file1 cmd1 cmd2 file2"); return (FALSE); } return (TRUE); } t_boolean check_open(int *fd) { if (*fd == ERROR) { perror("open error"); return (FALSE); } return (TRUE); } t_boolean check_access(char *str[]) { char *file1; char *file2; int read; int write; read = R_OK; write = W_OK; file1 = str[1]; file2 = str[4]; if (access(f.. 2024. 3. 23.
[PIPEX / C] 메인 함수 흐름 및 fork()-wait()에 대하여 우선 파이프 엑스의 main함수를 작성했다. 파이프를 연결해서 출력하는 결과를 저장하려면 우선 읽는 파일 설정과 출력 파일 설정이 필요하다. pipex 읽기 전용 - 출력 전용 파일 만들기 pipex.infile = open(argv[1], O_RDONLY); pipex.outfile = open(argv[4], O_WRONLY | O_CREAT | O_TRUNC, 0644); open(fd, open_option, mod); 특정 파일의 옵션과 권한을 설정한다. if (!sanity_check(argc, argv, &pipex)) return (0); if (!check_fork(&pid1)) return (0); 무결성 검사를 통해 인자의 개수, 파일접근 권한 등 초기 조건을 검사 fork함수의 호출.. 2024. 3. 23.