null
vuild_
Nodes
Flows
Hubs
Login
MENU
Notifications
Login
⌂
c-lang-advanced
Structure
advanced-pointers
•
Function Pointer
•
Pointer to Pointer
•
Void Pointer
data-structures
•
Linked List
•
Stack & Queue
•
Tree & Graph
algorithms
•
Sorting Algorithms
•
Complexity Analysis
bit-ops
•
Bitwise Operators
•
Bit Fields
•
Bit Tricks
system-prog
•
Process
•
Signal
•
IPC (Inter-Process Communication)
concurrency
•
Threads Basics
•
Mutex & Semaphore
•
Race Condition
optimization
•
Compiler Flags
•
Cache Locality
•
Profiling
design-patterns
•
OOP in C
•
Callback Pattern
•
State Machine
project
•
Mini Shell
•
TCP Echo Server
Flow Structure
Bit Tricks
12 / 25
Signal
☆ Star
↗ Full
Process
#c
#c-lang
#advanced
#system-programming
#process
@devpc
|
2026-03-29 13:49:34
|
GET /api/v1/flows/6/nodes/76?fv=1&nv=1
Context:
Flow v1
→
Node v1
0
Views
1
Calls
# Process > fork/exec/wait, 프로세스 생성·종료 흐름 ## 학습 목표 - `fork()`로 자식 프로세스를 생성하는 방법을 이해한다 - `exec()` 계열 함수로 프로세스 이미지를 교체한다 - `wait()`으로 자식 프로세스의 종료를 처리한다 ## 내용 ### fork() ```c #include <unistd.h> #include <sys/wait.h> pid_t pid = fork(); if (pid < 0) { perror("fork failed"); } else if (pid == 0) { // 자식 프로세스 printf("Child PID: %d\n", getpid()); } else { // 부모 프로세스 printf("Parent PID: %d, Child: %d\n", getpid(), pid); } ``` ### exec() ```c // 자식에서 다른 프로그램 실행 if (pid == 0) { execlp("ls", "ls", "-l", NULL); perror("exec failed"); // exec 성공 시 이 줄은 실행되지 않음 exit(1); } ``` ### wait() ```c int status; pid_t child = wait(&status); if (WIFEXITED(status)) printf("Child exited with code %d\n", WEXITSTATUS(status)); ``` ### 전체 흐름 ``` 부모: fork() ──────────────────────────── wait() ──► 종료 처리 └── 자식: exec("ls") → ls 실행 → exit() ``` ## 참고 - `fork()` 후 `exec()` 없이 종료된 자식은 부모가 `wait()`하지 않으면 좀비(zombie) 프로세스가 된다
Bit Tricks
Signal
// COMMENTS
ON THIS PAGE
No content selected.