---
# System prepended metadata

title: 作業系統 - Process Concept

---

# 作業系統 - Process Concept
![](https://i.imgur.com/vnIHtvp.png)
藉由簡單的程式來呈現process的建立過程
```c=
#include<stdio.h>
#include<unistd.h>
#include<sys/wait.h>
int main(){
	int A;
	//fork another process
	A=fork();

	if(A==0){//child process
		printf("this is from child process\n");
		execlp("/bin/ls","ls",NULL);
        //execlp find the file to execute
	}else{//parent process
		printf("this is form parent process\n");
		int pid = wait(NULL);//wait child process
		printf("Child %d completes\n",pid);
	}
	printf("process ends %d\n",A);
}
```
透過execlp來作為exec()結尾的NULL就代表結束exit()。
## 執行結果
```
this is form parent process
this is from child process
1.cpp   1.o     linux.o liunx.c
Child 16628 completes
process ends 16628
```