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

/ 2,139评论 / 8410阅读 / 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. Williamfug说道:

    canadian drug stores: canadadrugpharmacy com – canada cloud pharmacy

  2. DavidTaK说道:

    reputable mexican pharmacies online best online pharmacies in mexico mexico pharmacy

  3. Williamfug说道:

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

  4. Jeromeviaph说道:

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

  5. DonaldtAg说道:

    canadian pharmacy online: canadian online drugstore – canadian pharmacy online

  6. Felipelam说道:

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

  7. DavidTaK说道:

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

  8. Williamfug说道:

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

  9. DavidTaK说道:

    rate canadian pharmacies ordering drugs from canada canadian pharmacy cheap

  10. Georgefrege说道:

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

  11. Jamesexite说道:

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

  12. DavidBiolo说道:

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

  13. Elmersoalf说道:

    super kamagra kamagra pills п»їkamagra

  14. Tylerreunk说道:

    http://cenforce.pro/# buy cenforce

  15. Charlesvox说道:

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

  16. Elmersoalf说道:

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

  17. Charlesvox说道:

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

  18. Jamesexite说道:

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

  19. Tylerreunk说道:

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

  20. Georgefrege说道:

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

  21. Jamesexite说道:

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

  22. Elmersoalf说道:

    buy Kamagra kamagra Kamagra 100mg price

  23. Charlesvox说道:

    https://cenforce.pro/# buy cenforce

  24. Elmersoalf说道:

    Vardenafil buy online Cheap Levitra online Levitra online pharmacy

  25. Charlesvox说道:

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

  26. Jamesexite说道:

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

  27. Elmersoalf说道:

    cheapest cenforce cenforce for sale Cenforce 150 mg online

  28. Jamesexite说道:

    buy cenforce: cenforce.pro – cheapest cenforce

  29. Elmersoalf说道:

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

  30. Charlesvox说道:

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

  31. Georgefrege说道:

    Vardenafil price: Generic Levitra 20mg – Vardenafil buy online

  32. DavidBiolo说道:

    http://cialist.pro/# cheapest cialis

  33. Elmersoalf说道:

    Cenforce 150 mg online Purchase Cenforce Online cenforce.pro

  34. Charlesvox说道:

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

  35. Jamesexite说道:

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

  36. Elmersoalf说道:

    Buy Vardenafil 20mg Cheap Levitra online Vardenafil price

  37. Charlesvox说道:

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

  38. Elmersoalf说道:

    buy viagra here Cheap Viagra 100mg Viagra tablet online

  39. Jamesexite说道:

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

  40. Tylerreunk说道:

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

  41. DavidBiolo说道:

    http://cialist.pro/# Tadalafil Tablet

  42. Elmersoalf说道:

    super kamagra buy kamagra online buy Kamagra

  43. Charlesvox说道:

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

  44. Tylerreunk说道:

    https://cenforce.pro/# buy cenforce

  45. Jamesexite说道:

    buy kamagra online usa: kamagra – super kamagra

  46. Georgefrege说道:

    cenforce for sale: cheapest cenforce – cheapest cenforce

  47. w-495.ru说道:

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

  48. Charlesvox说道:

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

  49. Elmersoalf说道:

    Viagra Tablet price Buy Viagra online Sildenafil 100mg price

回复 Georgefrege 取消回复

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