[linux操作系统实验]进程的控制(execl()第二个传参为什么是可执行程序名)

/ 1,840评论 / 7642阅读 / 1点赞

问题

实验示例代码中,调用execl()时,第二个传参为什么会是可执行程序名:

execl("/bin/ls", "ls", "-l", "-color", NULL)

#include <iostream>
using namespace std;

int main(int aNum, char** aStr)
{
        cout << "hello,coolight" << endl;
        cout << "main参数列表:" << endl;
        for(int i = 0; i < aNum; ++i)
                cout << i + 1 << " : " << aStr[i] << endl;

        return 0;
}

实验具体内容

实验内容

涉及的系统调用

在Linux中fork()是一个非常有用的系统调用,但在Linux中建立进程除了fork()之外,也可用与fork() 配合使用的exec()。

exec()系列

exec()fork()联合使用

int status;
     ............
if (fork() == 0)
{
     ............
     execl(...);
     ............
}
wait(&status);

wait()

exit()

源代码

#include <iostream>
#include <unistd.h>
#include "sys/wait.h"
#include "sys/types.h"
using namespace std;
int main()
{
        cout << "<< coolgiht" << endl;
        int status, renum_fork = fork();
        if(renum_fork == -1){
                cout << "<< fork error!" << endl;
        }else if(renum_fork == 0){ //子进程
                execl("./hello", "hello", "-1", "-2", NULL);
                cout << "execl error!" << endl;
        }else{  //父进程
                wait(NULL);
                cout << "<< 完成!" << endl;
        }
        return 0;
}
#include <iostream>
using namespace std;
int main(int aNum, char** aStr)
{
        cout << "hello,coolight" << endl;
        cout << "main参数列表:" << endl;
        for(int i = 0; i < aNum; ++i)

                cout << i + 1 << " : " << aStr[i] << endl;

        return 0;
}

运行结果截图

思考

  1. ads508说道:

    Hi! I could have sworn I’ve visited your blog before but after going through a few of the posts I realized it’s new to
    me. Anyhow, I’m definitely pleased I came across it and I’ll be book-marking it and checking
    back often!

  2. PhilipBup说道:

    canadian prescription pharmacy rx pharmacy no prescription canadian pharmacy world coupon

  3. Armandosed说道:

    https://medicationnoprescription.pro/# no prescription medicines

  4. MatthewDoolo说道:

    erectile dysfunction medications online: online ed medicine – get ed meds today

  5. Armandosed说道:

    http://medicationnoprescription.pro/# buy prescription drugs online without doctor

  6. PhilipBup说道:

    order medication without prescription canadian pharmacy no prescription required buying drugs without prescription

  7. HarveyBeemi说道:

    http://edpill.top/# ed meds cheap

  8. Armandosed说道:

    https://edpill.top/# how to get ed meds online

  9. MatthewDoolo说道:

    prescription drugs online: rx pharmacy coupons – canadian pharmacy coupon

  10. Josephtrink说道:

    https://amoxicillina.top/# where can i buy amoxicillin over the counter uk

  11. JamesLot说道:

    order generic clomid without rx can i buy clomid without a prescription where to buy cheap clomid no prescription

  12. MichaelPycle说道:

    prednisone 20mg price in india: prednisone 10mg online – prednisone 40 mg rx

  13. BrainSaw说道:

    http://stromectola.top/# ivermectin 3 mg

  14. MichaelPycle说道:

    can i purchase generic clomid tablets: can i buy clomid online – can i order generic clomid now

  15. BryanSturf说道:

    ivermectin 3 mg dose: ivermectin new zealand – stromectol uk buy

  16. dobry sklep说道:

    Wow, marvelous blog format! How lengthy have you been blogging for?
    you made blogging look easy. The entire look of your site is fantastic,
    let alone the content material! You can see similar here dobry sklep

  17. novoluxe.top说道:

    Wow, awesome weblog structure! How lengthy have you ever been running a blog for?
    you made blogging glance easy. The full look of your site is excellent, as neatly as
    the content material! You can see similar here sklep online

  18. Wow, awesome weblog layout! How lengthy have you been blogging for?

    you make blogging glance easy. The overall look of
    your site is excellent, as neatly as the content material!
    You can see similar here dobry sklep

  19. JamesLot说道:

    ivermectin cost uk stromectol medication ivermectin 90 mg

  20. 69hub.pl说道:

    Wow, incredible weblog layout! How long have you been running a blog for?
    you make blogging look easy. The total glance of your site is magnificent,
    as neatly as the content! You can see similar here sklep internetowy

  21. MichaelPycle说道:

    cheap zithromax pills: can you buy zithromax over the counter in mexico – buy zithromax without prescription online

  22. Mathew说道:

    Wow, wonderful blog layout! How long have you been running a blog for?

    you make blogging look easy. The full look of your website is magnificent, as smartly as the content material!
    You can see similar here e-commerce

  23. najlepszy sklep说道:

    Wow, superb weblog structure! How long have you been running a blog for?
    you made blogging glance easy. The overall look of your website is wonderful,
    let alone the content! You can see similar here sklep

  24. Wow, amazing blog format! How lengthy have you
    ever been blogging for? you made running a blog glance easy.
    The whole glance of your website is great, as smartly as the content material!
    You can see similar here sklep

  25. ecommerce说道:

    Wow, marvelous weblog layout! How lengthy have you ever been running a blog for?
    you make blogging glance easy. The overall look of your site is magnificent, as smartly
    as the content material! You can see similar here sklep online

  26. MichaelPycle说道:

    cheap clomid tablets: generic clomid for sale – buy generic clomid without rx

  27. BrainSaw说道:

    https://prednisonea.store/# prednisone cost us

  28. najlepszy sklep说道:

    Wow, wonderful weblog layout! How long have you ever
    been blogging for? you make blogging glance easy. The whole look of your web site is fantastic, let alone the content!
    You can see similar here sklep online

  29. JamesLot说道:

    can i purchase clomid now can i order clomid for sale buying clomid for sale

  30. dobry sklep说道:

    Wow, fantastic weblog structure! How long have you been running a blog for?

    you made running a blog look easy. The overall glance of your web site is
    great, let alone the content material! You can see
    similar here ecommerce

  31. MichaelPycle说道:

    prednisone pill: prednisone tabs 20 mg – average price of prednisone

  32. BryanSturf说道:

    can you get clomid: where to get clomid price – buy clomid without prescription

  33. DomenicDobby说道:

    purchase zithromax z-pak: zithromax azithromycin – generic zithromax azithromycin

  34. Josephtrink说道:

    https://amoxicillina.top/# amoxicillin 500 mg where to buy

  35. sklep说道:

    Wow, superb weblog structure! How lengthy have you ever been blogging
    for? you make blogging glance easy. The total look of your web site is magnificent, as smartly as the content
    material! You can see similar here ecommerce

  36. BrainSaw说道:

    http://clomida.pro/# where buy generic clomid

  37. Fabian说道:

    Wow, amazing weblog format! How long have you been running a blog for?
    you made blogging glance easy. The total look of your website is magnificent,
    let alone the content! You can see similar here najlepszy sklep

  38. ecommerce说道:

    Wow, superb weblog layout! How lengthy have you been running a blog for?
    you make running a blog glance easy. The entire look of your web site is wonderful, as smartly as the content!
    You can see similar here sklep internetowy

  39. sklep online说道:

    Wow, wonderful weblog format! How long have you been running a blog for?
    you made blogging glance easy. The entire look of your site
    is great, let alone the content material! You can see similar here sklep online

  40. JamesLot说道:

    buy generic clomid prices can i order cheap clomid for sale can i order generic clomid without dr prescription

  41. MichaelPycle说道:

    amoxicillin 825 mg: can you buy amoxicillin uk – amoxil pharmacy

  42. Wow, incredible blog format! How lengthy have you ever been running a blog for?
    you made blogging glance easy. The full look of your site is great,
    let alone the content! You can see similar here sklep internetowy

  43. silvoria.shop说道:

    Wow, superb weblog layout! How lengthy have you been running a blog for?
    you make blogging glance easy. The entire glance of your website is excellent, as smartly as the content!

    You can see similar here najlepszy sklep

  44. Wow, awesome blog format! How long have you been blogging for?
    you make blogging look easy. The overall look of your website is great, as smartly as the content!
    You can see similar here sklep internetowy

  45. ecommerce说道:

    Wow, fantastic weblog layout! How long have you been blogging
    for? you made running a blog look easy. The total glance of
    your web site is fantastic, as well as the content material!
    You can see similar here e-commerce

  46. podusia.top说道:

    Wow, awesome weblog structure! How lengthy have you been blogging
    for? you made blogging glance easy. The total
    look of your web site is great, let alone the content! You can see similar here najlepszy sklep

  47. BryanSturf说道:

    cost of amoxicillin prescription: amoxicillin 50 mg tablets – amoxicillin 500 mg price

  48. MichaelPycle说道:

    cost clomid without a prescription: can i get clomid no prescription – can i purchase generic clomid without rx

  49. JamesLot说道:

    zithromax 500 mg zithromax 250 mg australia buy zithromax 1000 mg online

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注