zoukankan      html  css  js  c++  java
  • 进程学习笔记(一)

    进程好难啊,当初OS课仅仅是学了一些调度算法之类的东西,对wait之类的命令理解还不够,看来要尽快补上了。

    进程学习中提到了fork()叉子的概念,可以从主进程中拓展出一个子进程(pid==0)和一个父进程(pid>0)。

    如果换成vfork(),则不会产生这种效果

    #include <stdio.h>
    #include <unistd.h>
    #include <sys/types.h>
    int main(){
            pid_t pid;
            char *message;
            pid = fork();
            int n;
            if(pid==0){
                    message = "This is the child";
                    n = 5;
                    printf("%d\n",pid);
            }
            else if (pid>100 && pid<1000){
                    message = "Pid is 100~1000";
                    n = 7;
                    printf("%d\n",pid);
            }
            else{
                    message = "This is the parent";
                    n = 3;
                    printf("%d\n",pid);
                            
            }
            while(n--){
                    puts(message);
                    sleep(1);
            }
            return 0;
    }

    还应该去学一些进程间通信的知识。。加油。

  • 相关阅读:
    git 合并两个仓库
    git 合并两个仓库
    操作系统
    域名
    域名
    .NET Framework基本概念
    .NET Framework基本概念
    拓扑排序
    PHP 数组
    PHP Switch 语句
  • 原文地址:https://www.cnblogs.com/markliu/p/2798044.html
Copyright © 2011-2022 走看看