Computer operating system - Linux: reference textbook examples, use the system call fork, create a new process, and execute, java: use multi-thread library, create multi-thread, and execute

1. Purpose of the experiment:

1. Linux: Refer to the textbook example, use the system call fork, create a new process, and execute

2. Java: use multi-thread library, create multi-thread, and execute

2. Experimental principle:

       The parent process (thread) outputs the student ID and process ID (thread name),

       Child process (thread) output name and process number (thread name)

3. Experimental environment: Vmware virtual machine and IDEA

4. Experimental steps:

#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. Experimental data recording and processing:

 

 

Guess you like

Origin blog.csdn.net/WZY22502701/article/details/130529963