45intmain(void){6printf("HelloWorld!!.\n");7return0;8}1//example_2.c2#include3#include4#include5#include6#include7#include8#include

亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

操作系統 : 第一周作業

系統 1854 0
      
        1
      
      
        //
      
      
        example_1.c
      
      
        2
      
      
        3
      
       #include <stdio.h>


      
        4
      
      
        5
      
      
        int
      
       main(
      
        void
      
      
        ){


      
      
        6
      
           printf(
      
        "
      
      
        Hello World!! .\n
      
      
        "
      
      
        );


      
      
        7
      
      
        return
      
      
        0
      
      
        ;


      
      
        8
      
       }
    

?

?

      
         1
      
      
        //
      
      
        example_2.c
      
      
         2
      
       #include <unistd.h>


      
         3
      
       #include <stdarg.h>


      
         4
      
       #include <time.h>


      
         5
      
       #include <sys/types.h>


      
         6
      
       #include <sys/wait.h>


      
         7
      
       #include <stdio.h>


      
         8
      
       #include <stdlib.h>


      
         9
      
      
        10
      
      
        int
      
       tprintf(
      
        const
      
      
        char
      
       *
      
        fmt, ...){


      
      
        11
      
      
            va_list args;


      
      
        12
      
      
        struct
      
       tm *
      
        tstruct;


      
      
        13
      
      
            time_t tsec;


      
      
        14
      
           tsec =
      
         time(NULL);


      
      
        15
      
           tstruct = localtime(&
      
        tsec);


      
      
        16
      
           printf(
      
        "
      
      
        %02d:%02d:%5d|
      
      
        "
      
      , tstruct->tm_hour, tstruct->tm_min, tstruct->
      
        tm_sec, getpid());


      
      
        17
      
      
            va_start(args, fmt);


      
      
        18
      
      
        return
      
      
         vprintf(fmt, args);


      
      
        19
      
      
        }


      
      
        20
      
      
        int
      
      
         main(){


      
      
        21
      
      
        int
      
       i=
      
        0
      
      , j=
      
        0
      
      
        ;


      
      
        22
      
      
        int
      
      
         pid;


      
      
        23
      
           printf(
      
        "
      
      
        Hello from Parent Process , PID is %d.\n
      
      
        "
      
      
        , getpid());


      
      
        24
      
           pid =
      
         fork();


      
      
        25
      
      
        if
      
      (pid == 
      
        0
      
      
        ){


      
      
        26
      
               sleep(
      
        1
      
      
        );


      
      
        27
      
      
        for
      
      (i=
      
        0
      
      ; i<
      
        3
      
      ; ++
      
        i){


      
      
        28
      
                   printf(
      
        "
      
      
        Hello from Child Process %d. %d times\n
      
      
        "
      
      , getpid(), i+
      
        1
      
      
        );;


      
      
        29
      
                   sleep(
      
        1
      
      
        );


      
      
        30
      
      
                }


      
      
        31
      
      
            }


      
      
        32
      
      
        else
      
      
        if
      
      (pid != -
      
        1
      
      
        ){


      
      
        33
      
               tprintf(
      
        "
      
      
        Parent forked one child process -- %d.\n
      
      
        "
      
      
        , pid);


      
      
        34
      
               tprintf(
      
        "
      
      
        Parent is waiting for child to exit.\n
      
      
        "
      
      
        );


      
      
        35
      
               waitpid(pid, NULL, 
      
        0
      
      
        );


      
      
        36
      
               tprintf(
      
        "
      
      
        Child Process has exited.\n
      
      
        "
      
      
        );


      
      
        37
      
               tprintf(
      
        "
      
      
        Parent had exited.\n
      
      
        "
      
      
        );


      
      
        38
      
      
            }


      
      
        39
      
      
        else
      
       tprintf(
      
        "
      
      
        Everyting was done without error\n
      
      
        "
      
      
        );


      
      
        40
      
      
        return
      
      
        0
      
      
        ;


      
      
        41
      
       }
    

?

    ?
    
example_3.c
      
         1
      
       #include <unistd.h>


      
         2
      
       #include <stdarg.h>


      
         3
      
       #include <time.h>


      
         4
      
       #include <sys/types.h>


      
         6
      
       #include <sys/wait.h>


      
         7
      
       #include <stdio.h>


      
         8
      
       #include <stdlib.h>


      
         9
      
      
        10
      
      
        int
      
       tprintf(
      
        const
      
      
        char
      
       *
      
        fmt, ...);


      
      
        11
      
      
        12
      
      
        int
      
       main(
      
        int
      
       argc, 
      
        char
      
      
        const
      
       *
      
        argv[])


      
      
        13
      
      
        {


      
      
        14
      
      
        int
      
      
         pid;


      
      
        15
      
           pid =
      
         fork();


      
      
        16
      
      
        if
      
      (pid == 
      
        0
      
      
        ){


      
      
        17
      
               sleep(
      
        5
      
      
        );


      
      
        18
      
               tprintf(
      
        "
      
      
        Hello from Child Process !\n
      
      
        "
      
      
        );


      
      
        19
      
               tprintf(
      
        "
      
      
        I am calling exec.\n
      
      
        "
      
      
        );


      
      
        20
      
               execl(
      
        "
      
      
        /bin/ps
      
      
        "
      
      , 
      
        "
      
      
        -a
      
      
        "
      
      
        , NULL);


      
      
        21
      
               tprintf(
      
        "
      
      
        You should never see this because child is already gone.\n
      
      
        "
      
      
        );


      
      
        22
      
      
            }


      
      
        23
      
      
        else
      
      
        if
      
      (pid != -
      
        1
      
      
        ){


      
      
        24
      
               tprintf(
      
        "
      
      
        Hello from Parent, pid %d.\n
      
      
        "
      
      
        , getpid());


      
      
        25
      
               sleep(
      
        1
      
      
        );


      
      
        26
      
               tprintf(
      
        "
      
      
        Parent forked process %d.\n
      
      
        "
      
      
        , pid);


      
      
        27
      
               sleep(
      
        1
      
      
        );


      
      
        28
      
               tprintf(
      
        "
      
      
        Parent is waiting for child to exit.\n
      
      
        "
      
      
        );


      
      
        29
      
               waitpid(pid, NULL, 
      
        0
      
      
        );


      
      
        30
      
               tprintf(
      
        "
      
      
        Parent had exited.\n
      
      
        "
      
      
        );


      
      
        31
      
      
            }


      
      
        32
      
      
        else
      
       tprintf(
      
        "
      
      
        Everything was done without error.\n
      
      
        "
      
      
        );


      
      
        33
      
      
        return
      
      
        0
      
      
        ;


      
      
        34
      
      
        }


      
      
        35
      
      
        36
      
      
        int
      
       tprintf(
      
        const
      
      
        char
      
       *
      
        fmt, ...){


      
      
        37
      
      
            va_list args;


      
      
        38
      
      
        struct
      
       tm *
      
        tstruct;


      
      
        39
      
      
            time_t tsec;


      
      
        40
      
           tsec =
      
         time(NULL);


      
      
        41
      
           tstruct = localtime(&
      
        tsec);


      
      
        42
      
           printf(
      
        "
      
      
        %02d:%02d:%5d|
      
      
        "
      
      , tstruct->tm_hour, tstruct->tm_min, tstruct->
      
        tm_sec, getpid());


      
      
        43
      
      
            va_start(args, fmt);


      
      
        44
      
      
        return
      
      
         vprintf(fmt, args);


      
      
        45
      
       }
    

?

?

homework_1.c

      
         1
      
       #include <stdio.h>


      
         2
      
       #include <unistd.h>


      
         3
      
       #include <sys/types.h>


      
         4
      
       #include <sys/wait.h>


      
         5
      
       #include <stdlib.h>


      
         6
      
      
         7
      
      
        int
      
      
         main(){


      
      
         8
      
      
        int
      
      
         pid;


      
      
         9
      
           pid =
      
         fork();


      
      
        10
      
      
        if
      
      (pid > 
      
        0
      
      
        ){


      
      
        11
      
               pid =
      
         fork();


      
      
        12
      
      
        if
      
      (pid >
      
        0
      
      
        ){


      
      
        13
      
                   printf(
      
        "
      
      
        parent : pid =  %d\n
      
      
        "
      
      
        , getpid());


      
      
        14
      
                   waitpid(pid, NULL, 
      
        0
      
      
        );


      
      
        15
      
                   printf(
      
        "
      
      
        Child Process has exited.\n
      
      
        "
      
      
        );


      
      
        16
      
                   printf(
      
        "
      
      
        Parent had exited\n
      
      
        "
      
      
        );


      
      
        17
      
                   exit(
      
        1
      
      
        );


      
      
        18
      
      
                }


      
      
        19
      
      
        else
      
      
        if
      
      (pid == 
      
        0
      
      
        ){


      
      
        20
      
                   printf(
      
        "
      
      
        child 2 : pid =  %d\n
      
      
        "
      
      
        , getpid());


      
      
        21
      
                   exit(
      
        0
      
      
        );


      
      
        22
      
      
                }


      
      
        23
      
      
            }


      
      
        24
      
      
        else
      
      
        if
      
      (pid ==
      
        0
      
      
        ){


      
      
        25
      
               printf(
      
        "
      
      
        child 1 : pid =  %d\n
      
      
        "
      
      
        , getpid());


      
      
        26
      
               exit(
      
        0
      
      
        );


      
      
        27
      
      
            }


      
      
        28
      
      
        return
      
      
        0
      
      
        ;


      
      
        29
      
       }
    

?

homework_2.c

      
         1
      
       #include <stdio.h>


      
         2
      
       #include <unistd.h>


      
         3
      
       #include <sys/types.h>


      
         4
      
       #include <sys/wait.h>


      
         5
      
       #include <stdlib.h>


      
         6
      
      
         7
      
      
        int
      
      
         main(){


      
      
         8
      
      
        int
      
      
         pid;


      
      
         9
      
      
        int
      
      
         n, i;


      
      
        10
      
           scanf(
      
        "
      
      
        %d
      
      
        "
      
      , &
      
        n);


      
      
        11
      
      
        for
      
      (i=
      
        0
      
      ;i<n;++
      
        i){


      
      
        12
      
               pid =
      
         fork();


      
      
        13
      
      
        if
      
      (pid == 
      
        0
      
      
        ){


      
      
        14
      
                   printf(
      
        "
      
      
        child : pid : %d , ppid : %d \n
      
      
        "
      
      
        , getpid(), getppid());


      
      
        15
      
      
        continue
      
      
        ;


      
      
        16
      
      
                }


      
      
        17
      
      
        else
      
      
        if
      
      (pid > 
      
        0
      
      
        ){


      
      
        18
      
                   waitpid(pid, NULL, 
      
        0
      
      
        );


      
      
        19
      
                   exit(
      
        1
      
      
        );


      
      
        20
      
      
                }


      
      
        21
      
      
            }


      
      
        22
      
      
        return
      
      
        0
      
      
        ;


      
      
        23
      
       }
    

?

      #include <stdio.h>
      
        

#include 
      
      <unistd.h>
      
        

#include 
      
      <sys/wait.h>
      
        

#include 
      
      <stdlib.h>


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

{

    
      
      
        int
      
       pid[
      
        5
      
      
        ];

    
      
      
        int
      
      
         i;

    
      
      
        for
      
      (i=
      
        0
      
      ;i<
      
        5
      
      ;++
      
        i){

        pid[i] 
      
      =
      
         fork();

        
      
      
        if
      
      (pid[i]==
      
        0
      
      
        ){

            printf(
      
      
        "
      
      
        zi(%d) pid:  %d,  fu pid: %d \n
      
      
        "
      
      , i+
      
        1
      
      
        , getpid(), getppid());

            exit(
      
      
        0
      
      
        );

        }

    }

    
      
      
        for
      
      (i=
      
        0
      
      ;i<
      
        5
      
      ;++
      
        i)

        waitpid(pid[i], NULL, 
      
      
        0
      
      
        );

    printf(
      
      
        "
      
      
        fupid: %d \n
      
      
        "
      
      
        , getpid());

    
      
      
        return
      
      
        0
      
      
        ;

}
      
    

?

?

?

?

?

?

?

?

?

?

?

?

操作系統 : 第一周作業


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 一级毛片一级片 | 国产一级二级在线观看 | 欧美日韩精品一区二区在线线 | 四虎永久在线视频 | 精品久久久久久中文字幕无碍 | 日韩 欧美 中文字幕 不卡 | 国产a毛片高清视 | 日本免费一区二区三区毛片 | 日韩精品成人a在线观看 | 亚洲视频精选 | 99久久香蕉国产综合影院 | 国内精品51视频在线观看 | 一级特黄特色aa大片 | 五月开心六月伊人色婷婷 | 精品国产日韩一区三区 | 内衣办公室动漫久久影院 | 国产精品亚洲欧美日韩一区在线 | 884hutv四虎永久黄网 | 日日干夜夜艹 | 久久精品中文字幕不卡一二区 | 四虎永久免费影院在线 | 欧美成人中文字幕dvd | 91精品国产福利在线观看性色 | 日日夜人人澡人人澡人人看免 | 精品精品国产高清a毛片 | 一区二区三区免费视频观看 | 真人毛片免费拍拍拍aa视频 | 四虎综合九九色九九综合色 | 亚洲精品蜜桃久久久久久 | 欧美一区二区三区香蕉视 | 伊人在综合 | 日本伦理中文字幕 | 国产亚洲综合久久 | 国产人成精品综合欧美成人 | 亚洲福利影院 | 亚洲tv精品一区二区三区 | 成人日韩欧美 | 日本不卡视频在线视频观看 | www.欧美激情| 久久久久久夜精品精品免费啦 | 九九九精品 |