计算机操作系统——Linux:参考教材例子,使用系统调用fork,创建新进程,并执行,java:使用多线程库,创建多线程,并执行

1.实验目的:

1、Linux:参考教材例子,使用系统调用fork,创建新进程,并执行

2、Java:使用多线程库,创建多线程,并执行

2.实验原理:

       父进程(线程)输出 学号和进程号(线程名),

       子进程(线程)输出 姓名和进程号(线程名)

3.实验环境:Vmware虚拟机和IDEA

4.实验步骤:

#include<stdio.h>

void main(int argc,char *argv[])

{

       int pid;

         /*fork another process*/

       pid =fork();

       if(pid<0){    /*error process*/

             printf("Fork Failed");

       }

       else if(pid==0){      /*child process*/

            printf("jiangwang,process id is %d\n",getpid());

       }

       else{    /*parent process*/

            /*parent will wait for the chile to complete*/

           wait(NULL);

           printf("2104423309,process id is %d\n",getpid());

       }

}

5.实验数据记录与处理:

 

猜你喜欢

转载自blog.csdn.net/WZY22502701/article/details/130529963