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

/ 2,138评论 / 8398阅读 / 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. Jamesexite说道:

    cenforce.pro: Purchase Cenforce Online – Buy Cenforce 100mg Online

  2. Elmersoalf说道:

    Kamagra 100mg price kamagra oral jelly Kamagra 100mg

  3. WilliamRen说道:

    https://cytotec.club/# buy cytotec in usa

  4. Davidfrify说道:

    tamoxifenworld nolvadex for pct tamoxifen benefits

  5. RandallGuesE说道:

    lisinopril diuretic: lisinopril pills 2.5 mg – 3 lisinopril

  6. w-495.ru说道:

    психологическая помощь москва w-495.ru

  7. Davidfrify说道:

    zestoretic canada lisinopril pills for sale lisinopril 5 mg for sale

  8. RonaldSwobe说道:

    http://ciprofloxacin.tech/# cipro ciprofloxacin

  9. WilliamRen说道:

    http://cytotec.club/# purchase cytotec

  10. RandallGuesE说道:

    propecia buy: order propecia for sale – get propecia without a prescription

  11. Davidfrify说道:

    cytotec abortion pill cytotec buy online usa buy misoprostol over the counter

  12. WilliamRen说道:

    https://ciprofloxacin.tech/# where can i buy cipro online

  13. RandallGuesE说道:

    tamoxifen side effects forum: clomid nolvadex – how to lose weight on tamoxifen

  14. Davidfrify说道:

    propecia generics get generic propecia without rx order cheap propecia pill

  15. RonaldSwobe说道:

    https://finasteride.store/# order cheap propecia no prescription

  16. Davidfrify说道:

    lisinopril buy in canada lisinopril generic zestril 10mg price

  17. WilliamRen说道:

    http://ciprofloxacin.tech/# ciprofloxacin 500 mg tablet price

  18. RandallGuesE说道:

    Cytotec 200mcg price: buy cytotec in usa – cytotec online

  19. RandallGuesE说道:

    generic lisinopril: online pharmacy lisinopril – buy lisinopril in mexico

  20. Davidfrify说道:

    cost generic propecia buy cheap propecia for sale generic propecia tablets

  21. Davidfrify说道:

    lisinopril 3.5 mg lisinopril 125 mg lisinopril 40 mg generic

  22. WilliamRen说道:

    https://nolvadex.life/# tamoxifen vs clomid

  23. RonaldSwobe说道:

    http://lisinopril.network/# cost of lisinopril in mexico

  24. RandallGuesE说道:

    where can i buy nolvadex: alternatives to tamoxifen – tamoxifen generic

  25. WilliamRen说道:

    http://nolvadex.life/# tamoxifen bone density

  26. Davidfrify说道:

    antibiotics cipro ciprofloxacin mail online ciprofloxacin generic

  27. RandallGuesE说道:

    tamoxifen therapy: nolvadex for sale – nolvadex 20mg

  28. Davidfrify说道:

    buy ciprofloxacin ciprofloxacin mail online where can i buy cipro online

  29. RonaldSwobe说道:

    http://cytotec.club/# buy cytotec

  30. WilliamRen说道:

    http://lisinopril.network/# lisinopril 20 mg tablet cost

  31. RandallGuesE说道:

    ciprofloxacin 500 mg tablet price: ciprofloxacin over the counter – buy ciprofloxacin over the counter

  32. Davidfrify说道:

    buying generic propecia no prescription order generic propecia without rx buy cheap propecia for sale

  33. WilliamRen说道:

    http://lisinopril.network/# buy lisinopril online canada

  34. RandallGuesE说道:

    cost of cheap propecia now: cost generic propecia pill – how cÉ‘n i get cheap propecia pills

  35. Davidfrify说道:

    cytotec buy online usa buy cytotec online fast delivery cytotec pills buy online

  36. WilliamRen说道:

    https://nolvadex.life/# tamoxifen buy

  37. RandallGuesE说道:

    ciprofloxacin 500mg buy online: buy cipro – ciprofloxacin mail online

  38. WilliamRen说道:

    http://ciprofloxacin.tech/# cipro ciprofloxacin

  39. RandallGuesE说道:

    buy cytotec: Misoprostol 200 mg buy online – cytotec pills buy online

  40. Davidfrify说道:

    buy cipro online without prescription п»їcipro generic antibiotics cipro

  41. Davidfrify说道:

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

  42. WilliamRen说道:

    https://cytotec.club/# buy cytotec pills online cheap

  43. RandallGuesE说道:

    who should take tamoxifen: buy nolvadex online – tamoxifen benefits

  44. Davidfrify说道:

    cytotec online buy cytotec over the counter buy misoprostol over the counter

  45. RonaldSwobe说道:

    https://ciprofloxacin.tech/# buy ciprofloxacin over the counter

  46. WilliamRen说道:

    http://cytotec.club/# buy misoprostol over the counter

  47. RandallGuesE说道:

    cytotec pills online: purchase cytotec – buy cytotec online

  48. Davidfrify说道:

    cost generic propecia without insurance buy generic propecia without a prescription order propecia without a prescription

  49. WilliamRen说道:

    http://ciprofloxacin.tech/# ciprofloxacin order online

发表回复

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