熟悉命令ls,cd,pwd,mkdir,rm,mv,cp,cat,nl, more,less,head,tail,which,whereis,locate,find,xargs,wc,grep,cut,paste,tr,sort,uniq,join,comm,diff,patch,df,du,time
2. 查看系统进程:ps命令
3. 阅读实例代码fork1, 并编辑、编译、运行,记录程序的运行结果,尝试给出合理的解释。
Fork1.c
#include<stdio.h>
#include<unistd.h>
main( ) {
int pid;
pid=fork();
if (pid==-1)
{
printf(“fork failed.\n”);
return;
}
printf(“I’m the child.\n”);
printf(“I’m the parent.\n”);
return;
}
/*proc1.c演示有关进程操作*/
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
int main(int argc,char **argv)
{
pid_t pid,old_ppid,new_ppid;
pid_t child,parent;
parent=getpid(); /*获得本进程的PID*/
if((child=fork())<0){
fprintf(stderr,"%s:fork of child failed:%s\n",argv[0],strerror(errno));
exit(1);
}
else if(child==0){ /*此时是子进程被调度运行*/
old_ppid=getppid();
sleep(2);
new_ppid=getppid();
}
else {
sleep(1);
exit(0); /*父进程退出*/
}
/*下面仅子进程运行*/
printf("Original parent:%d\n",parent);
printf("Child:%d\n",getpid());
printf("Child's old ppid:%d\n",old_ppid);
printf("Child's new ppid:%d\n",new_ppid);
exit(0);
}
Fork2.c
#include<stdio.h>
include<unistd.h>
main()
{ int pid;
pid=fork();
if(pid==0) {
printf(“I’m the child.\n”);
execl(“/bin/ls”,”ls”,0);
perror(“exec error.\n”);
} else if(pid>0)
printf(“I’m the parent.\n”)
else printf(“fork failed.\n”);
printf(“program end.\n”);
}
进程与程序 在并发环境下,一个正在执行中的程序被称为进程。 程序是外存中的可执行文件。 进程实体由正文段、用户数据段和栈段组成。 多个进程可以同时执行同一个程序。