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

/ 2,156评论 / 8491阅读 / 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. JeromedUb说道:

    buy cytotec pills online cheap cytotec pills buy online cytotec pills buy online

  2. RussellVeila说道:

    buy doxycycline monohydrate: buy doxycycline online – buy doxycycline cheap

  3. RussellVeila说道:

    buy cipro: antibiotics cipro – purchase cipro

  4. Williamzew说道:

    Cytotec 200mcg price: cytotec abortion pill – Misoprostol 200 mg buy online

  5. JeromedUb说道:

    diflucan online canada diflucan 150 mg tablets buy diflucan online usa

  6. RussellVeila说道:

    cytotec buy online usa: order cytotec online – buy cytotec pills online cheap

  7. JeromedUb说道:

    buy doxycycline hyclate 100mg without a rx doxycycline 100mg doxycycline medication

  8. Archierut说道:

    https://diflucan.icu/# how can i get diflucan over the counter

  9. film porno说道:

    Everything is very open with a really clear clarification of the challenges.
    It was definitely informative. Your website is useful.
    Thank you for sharing!

  10. RussellVeila说道:

    cipro ciprofloxacin: ciprofloxacin generic price – ciprofloxacin 500mg buy online

  11. JamesSew说道:

    buy cytotec in usa: п»їcytotec pills online – order cytotec online

  12. Williamzew说道:

    ciprofloxacin generic: ciprofloxacin 500 mg tablet price – ciprofloxacin 500 mg tablet price

  13. RussellVeila说道:

    buy cytotec: buy cytotec online fast delivery – buy cytotec over the counter

  14. JeromedUb说道:

    buy cytotec in usa purchase cytotec order cytotec online

  15. RussellVeila说道:

    antibiotics cipro: cipro for sale – buy cipro online without prescription

  16. JeromedUb说道:

    tamoxifen and ovarian cancer where to get nolvadex tamoxifen and uterine thickening

  17. RussellVeila说道:

    doxycycline hyclate 100 mg cap: buy cheap doxycycline online – buy doxycycline online 270 tabs

  18. Williamzew说道:

    buy misoprostol over the counter: buy cytotec pills online cheap – buy misoprostol over the counter

  19. RussellVeila说道:

    doxycycline hyclate: doxycycline 200 mg – buy doxycycline hyclate 100mg without a rx

  20. JeromedUb说道:

    diflucan 100mg where to buy diflucan online how can i get diflucan over the counter

  21. Archierut说道:

    http://diflucan.icu/# diflucan in usa

  22. RussellVeila说道:

    buy diflucan 150mg: diflucan online purchase uk – diflucan from india

  23. JamesSew说道:

    doxycycline vibramycin: doxycycline 150 mg – doxy 200

  24. JeromedUb说道:

    ciprofloxacin 500 mg tablet price antibiotics cipro cipro

  25. RussellVeila说道:

    buy ciprofloxacin over the counter: buy cipro cheap – cipro

  26. Williamzew说道:

    buy doxycycline for dogs: generic doxycycline – doxycycline mono

  27. JeromedUb说道:

    diflucan 150 cost diflucan 1 pill diflucan usa

  28. RussellVeila说道:

    tamoxifen and depression: does tamoxifen cause weight loss – nolvadex gynecomastia

  29. RussellVeila说道:

    doxycycline 150 mg: buy doxycycline hyclate 100mg without a rx – order doxycycline online

  30. JeromedUb说道:

    diflucan drug diflucan 150 mg over the counter diflucan 200 mg daily

  31. Williamzew说道:

    order cytotec online: buy cytotec online – Cytotec 200mcg price

  32. Archierut说道:

    https://misoprostol.top/# cytotec abortion pill

  33. RussellVeila说道:

    buy doxycycline: doxycycline 100 mg – where to get doxycycline

  34. JeromedUb说道:

    ciprofloxacin cipro pharmacy buy cipro cheap

  35. RussellVeila说道:

    order doxycycline online: buy doxycycline without prescription – doxycycline generic

  36. RussellVeila说道:

    ciprofloxacin: cipro generic – buy ciprofloxacin over the counter

  37. Williamzew说道:

    over the counter diflucan pill: diflucan 200 mg price south africa – diflucan price south africa

  38. JeromedUb说道:

    buy doxycycline online without prescription buy doxycycline without prescription uk doxycycline vibramycin

  39. video porno说道:

    Superb, what a web site it is! This weblog provides useful information to us,
    keep it up.

  40. RussellVeila说道:

    buy cytotec in usa: buy cytotec over the counter – buy cytotec over the counter

  41. LarryAntic说道:

    buying from online mexican pharmacy mexican pharmacy reputable mexican pharmacies online

  42. RoscoeHailA说道:

    https://mexicanpharmgrx.com/# mexico drug stores pharmacies

  43. Chasetit说道:

    online pharmacy india: indian pharmacy – п»їlegitimate online pharmacies india

  44. LarryAntic说道:

    buying from online mexican pharmacy online pharmacy in Mexico mexican border pharmacies shipping to usa

  45. RoscoeHailA说道:

    http://mexicanpharmgrx.com/# mexican rx online

  46. DavidMus说道:

    ordering drugs from canada: Pharmacies in Canada that ship to the US – pharmacy canadian superstore

  47. Chasetit说道:

    certified canadian international pharmacy: International Pharmacy delivery – best rated canadian pharmacy

  48. RoscoeHailA说道:

    http://mexicanpharmgrx.com/# mexico drug stores pharmacies

  49. LarryAntic说道:

    mexico drug stores pharmacies Pills from Mexican Pharmacy mexico drug stores pharmacies

  50. LamarViz说道:

    canadian valley pharmacy: canadian pharmacy – canada discount pharmacy

发表回复

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