42seoul/minishell(2)
-
main함수 세번째 인자
main에 세번째 인자는 환경변수를 출력사고자 할 때 사용된다. 환경변수 출력 int main(int argc, char **argv, char *envp[]) { int i; i = 0; for (i = 0; envp[i]; i++) { printf("%s\n", envp[i]); } return (0); } USER=namgyupark SECURITYSESSIONID=186ba COMMAND_MODE=unix2003 __CFBundleIdentifier=com.microsoft.VSCode PATH=/opt/homebrew/bin:/opt/homebrew/bin:/Users/namgyupark/opt/anaconda3/bin:/Users/namgyupark/opt/anaconda3/condabin:/..
2021.05.19 -
dup()함수와 pipe()함수 fork()함수에 대한 정리
int main(int argc, char **argv, char *envp[]) { int x; pid_t pid; int fd[2]; int fd2; x = 0; pipe(fd); printf("%d, %d\n", fd[0], fd[1]); pid = fork();//자식 생성 if (pid > 0)//부모일 경우 { dup2(fd[1], 1);//표준출력 1이 fd[1]을 복제(고정)한다. //dup2함수 // int dup2(int fd, int fd2); // #include // fd2가 fd를 복제한다 write(fd[1], "hello\n", 6);//컴퓨터는 hello를 fd[1]을 통해서 읽는다. waitpid(pid, 0, 0);//자식이 끝날때까지 기다림 } else if (pid ..
2021.05.19