zoukankan      html  css  js  c++  java
  • [国嵌攻略][079][多进程程序设计]

    fork.c

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    
    void main(){
        int pid;
        
        pid = fork();
        printf("pid is %d
    ", pid);
        
        exit(0);
    }

    vfork.c

    #include <stdio.h>
    #include <stdlib.h>
    #include <sys/types.h>
    #include <unistd.h>
    
    void main(){
        int pid;
        
        pid = vfork();
        printf("pid is %d
    ", pid);
        
        exit(0);
    }

    wait.c

    #include <stdio.h>
    #include <stdlib.h>
    
    #include <unistd.h>
    #include <sys/types.h>
    #include <wait.h>
    
    void main(){
        int pid;
        
        pid = fork();
        if(pid > 0){
            wait(NULL);
            printf("pid is %d
    ", pid);
        }else{
            printf("pid is %d
    ", pid);
        }
        
        exit(0);
    }

    excel.c

    #include <stdio.h>
    #include <stdlib.h>
    
    #include <unistd.h>
    #include <sys/types.h>
    #include <wait.h>
    
    void main(){
        int pid;
        
        pid = fork();
        if(pid > 0){
            wait(NULL);
            printf("pid is %d
    ", pid);
        }else{
            execl("/bin/ls", "ls", NULL);
            printf("pid is %d
    ", pid);   //不会被执行
        }
        
        exit(0);
    }
  • 相关阅读:
    存储过程
    sdsdsd
    sdsdd
    sdsd
    sdasd
    mysql触发
    c#连接mysql答题步骤
    c#mysql数据库
    nginx
    linux如何查看端口被何进程占用
  • 原文地址:https://www.cnblogs.com/d442130165/p/5223552.html
Copyright © 2011-2022 走看看