程序是静态的概念,gcc xxx.c -o pro磁盘中生成pro文件,叫做程序。进程是程序的一次运动活动,通俗点意思就是程序跑起来了,系统中就多一个进程。
ps指令查看进程,,实际工作中,配合grep来查找程序中是否存在某一个进程
ps -aux|grep ---查看指定进程
top查看指令 类似任务管理器
每个进程都有一个非负整数表示唯一ID,叫做pid 类似身份证
pid=0:称为交换进程 作用是 进程调度
pid = 1 init进程 作用是系统初始化
getpid函数获取自身的进程标识符
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
int main()
{
pid_t pid;
pid = getpid();
printf("my pid is %d\n",pid);
while(1);
return 0;
}
getppid获取父进程的进程标识符
进程A创建了进程B 那么A叫父进程 B进程叫子进程