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

/ 1,849评论 / 7680阅读 / 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. DavidTaK说道:

    reputable mexican pharmacies online best online pharmacies in mexico mexico pharmacy

  2. Williamfug说道:

    Online medicine home delivery: best online pharmacy india – Online medicine home delivery

  3. Jeromeviaph说道:

    https://pharmworld.store/# canadian prescription pharmacy

  4. DonaldtAg说道:

    canadian pharmacy online: canadian online drugstore – canadian pharmacy online

  5. Felipelam说道:

    http://pharmworld.store/# cheapest pharmacy prescription drugs

  6. DavidTaK说道:

    canadianpharmacy com legal to buy prescription drugs from canada canadian pharmacy 365

  7. Williamfug说道:

    buy prescription drugs from india: reputable indian online pharmacy – cheapest online pharmacy india

  8. DavidTaK说道:

    rate canadian pharmacies ordering drugs from canada canadian pharmacy cheap

  9. Georgefrege说道:

    Buy Tadalafil 20mg: Generic Tadalafil 20mg price – Buy Cialis online

  10. Jamesexite说道:

    Cheap Sildenafil 100mg: viagras.online – Sildenafil Citrate Tablets 100mg

  11. DavidBiolo说道:

    https://viagras.online/# sildenafil over the counter

  12. Elmersoalf说道:

    super kamagra kamagra pills п»їkamagra

  13. Tylerreunk说道:

    http://cenforce.pro/# buy cenforce

  14. Charlesvox说道:

    http://cialist.pro/# Cialis over the counter

  15. Elmersoalf说道:

    Buy Tadalafil 20mg Generic Cialis price п»їcialis generic

  16. Charlesvox说道:

    https://levitrav.store/# Cheap Levitra online

  17. Jamesexite说道:

    Generic Levitra 20mg: Cheap Levitra online – Buy Vardenafil 20mg online

  18. Tylerreunk说道:

    https://cenforce.pro/# Cenforce 100mg tablets for sale

  19. Georgefrege说道:

    Generic Viagra online: viagras.online – Generic Viagra for sale

  20. Jamesexite说道:

    Cialis 20mg price in USA: buy cialis online – Tadalafil price

  21. Elmersoalf说道:

    buy Kamagra kamagra Kamagra 100mg price

  22. Charlesvox说道:

    https://cenforce.pro/# buy cenforce

  23. Elmersoalf说道:

    Vardenafil buy online Cheap Levitra online Levitra online pharmacy

  24. Charlesvox说道:

    https://cialist.pro/# Cialis 20mg price in USA

  25. Jamesexite说道:

    Buy Cialis online: buy cialis overseas – Cialis over the counter

  26. Elmersoalf说道:

    cheapest cenforce cenforce for sale Cenforce 150 mg online

  27. Jamesexite说道:

    buy cenforce: cenforce.pro – cheapest cenforce

  28. Elmersoalf说道:

    п»їLevitra price buy Levitra over the counter Buy generic Levitra online

  29. Charlesvox说道:

    http://kamagra.win/# Kamagra 100mg price

  30. Georgefrege说道:

    Vardenafil price: Generic Levitra 20mg – Vardenafil buy online

  31. DavidBiolo说道:

    http://cialist.pro/# cheapest cialis

  32. Elmersoalf说道:

    Cenforce 150 mg online Purchase Cenforce Online cenforce.pro

  33. Charlesvox说道:

    http://viagras.online/# sildenafil over the counter

  34. Jamesexite说道:

    Cialis without a doctor prescription: cialist.pro – Cialis 20mg price

  35. Elmersoalf说道:

    Buy Vardenafil 20mg Cheap Levitra online Vardenafil price

  36. Charlesvox说道:

    http://levitrav.store/# Vardenafil buy online

  37. Elmersoalf说道:

    buy viagra here Cheap Viagra 100mg Viagra tablet online

  38. Jamesexite说道:

    Cenforce 150 mg online: Cenforce 100mg tablets for sale – Buy Cenforce 100mg Online

  39. Tylerreunk说道:

    https://viagras.online/# Viagra Tablet price

  40. DavidBiolo说道:

    http://cialist.pro/# Tadalafil Tablet

  41. Elmersoalf说道:

    super kamagra buy kamagra online buy Kamagra

  42. Charlesvox说道:

    http://viagras.online/# Viagra without a doctor prescription Canada

  43. Tylerreunk说道:

    https://cenforce.pro/# buy cenforce

  44. Jamesexite说道:

    buy kamagra online usa: kamagra – super kamagra

  45. Georgefrege说道:

    cenforce for sale: cheapest cenforce – cheapest cenforce

  46. w-495.ru说道:

    индивидуальные консультации психолога
    w-495.ru

  47. Charlesvox说道:

    http://cialist.pro/# Generic Cialis without a doctor prescription

  48. Elmersoalf说道:

    Viagra Tablet price Buy Viagra online Sildenafil 100mg price

发表回复

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