t_cmd 구조체
t_cmd 구조체는 단일 명령어에 대한 정보를 저장합니다.
cmd: 이중 포인터로, 명령어와 그 인자들을 저장합니다. 예를 들어, "ls -l"이라는 명령어의 경우 {"ls", "-l", NULL}과 같은 형태로 저장됩니다.
path: 명령어의 전체 경로를 저장하는 문자열 포인터입니다. 예를 들어, "/bin/ls"와 같은 형태로 저장됩니다.
t_env 구조체
t_env 구조체는 pipex 프로그램의 전체적인 환경과 상태를 관리합니다.
envp: 환경 변수를 저장하는 이중 포인터입니다.
idx: 현재 처리 중인 명령어의 인덱스를 나타냅니다.
i_fd: 입력 파일의 파일 디스크립터를 저장합니다.
o_fd: 출력 파일의 파일 디스크립터를 저장합니다.
pipe_fd2: 파이프의 읽기와 쓰기 파일 디스크립터를 저장하는 배열입니다.
result: 프로그램의 실행 결과나 오류 코드를 저장합니다.
path: PATH 환경 변수에서 추출한 디렉토리 경로들을 저장하는 이중 포인터입니다.
pid: 자식 프로세스의 프로세스 ID를 저장합니다.
cmd: t_cmd 구조체의 포인터로, 실행할 명령어들의 배열을 가리킵니다.
이 구조체들을 사용하여 pipex 프로그램은 다음과 같은 작업을 수행할 수 있습니다:
환경 변수에서 PATH를 추출하고 저장합니다.
입력 및 출력 파일을 열고 관리합니다.
파이프를 생성하고 관리합니다.
각 명령어를 파싱하고 전체 경로를 찾습니다.
자식 프로세스를 생성하고 명령어를 실행합니다.
파이프를 통해 명령어 간 데이터를 전달합니다.
전체 프로세스의 실행 결과를 추적합니다.
이러한 구조를 통해 pipex 프로그램은 쉘의 파이프 기능을 효과적으로 모방할 수 있습니다
These structures represent the core data structures in the pipex program. I'll explain the meaning and role of each structure in detail.
t_cmd Structure
The t_cmd structure stores information about a single command.
cmd: A double pointer that stores the command and its arguments. For example, for a command like "ls -l", it would be stored as {"ls", "-l", NULL}.
path: A string pointer that stores the full path of the command. For instance, it might store "/bin/ls".
t_env Structure
The t_env structure manages the overall environment and state of the pipex program.
envp: A double pointer that stores environment variables.
idx: Represents the index of the command currently being processed.
i_fd: Stores the file descriptor of the input file.
o_fd: Stores the file descriptor of the output file.
pipe_fd: An array that stores the read and write file descriptors of the pipe.
result: Stores the execution result or error code of the program.
path: A double pointer that stores directory paths extracted from the PATH environment variable.
pid: Stores the process ID of the child process.
cmd: A pointer to the t_cmd structure, pointing to an array of commands to be executed.
Using these structures, the pipex program can perform the following tasks:
Extract and store PATH from environment variables.
Open and manage input and output files.
Create and manage pipes.
Parse each command and find its full path.
Create child processes and execute commands.
Transfer data between commands through pipes.
Track the execution result of the entire process.
Through this structure, the pipex program can effectively emulate the pipe functionality of a shell.
'C Language' 카테고리의 다른 글
here_doc 모드로 사용자 입력 받기 (0) | 2025.01.18 |
---|---|
< infile ls -l | wc -l >outfile (0) | 2025.01.18 |
divide_pivot 함수 pivoting algorithm (0) | 2025.01.15 |
메모리 할당 해제 문제 | Memory Allocating Freeing Problem (2) | 2025.01.13 |
최소값 최상단으로 소팅 함수 | sorting last function (0) | 2025.01.13 |