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

/ 9评论 / 930阅读 / 0点赞

问题

实验示例代码中,调用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. wwd.com说道:

    Hi, yes this article is genuinely good and I have learned lot of things from it on the topic
    of blogging. thanks.

  2. cq9说道:

    Greetings I am so delighted I found your blog
    page, I really found you by accident, while I was searching on Google for something
    else, Anyways I am here now and would just like to say thank you for a incredible post and a
    all round thrilling blog (I also love the
    theme/design), I don’t have time to read through it all at the
    moment but I have bookmarked it and also included your RSS feeds, so
    when I have time I will be back to read more,
    Please do keep up the great b.

  3. slot88说道:

    I think this is among the most significant info
    for me. And i am glad reading your article. But wanna remark on some general things, The web site style is great, the
    articles is really excellent : D. Good job, cheers

  4. zECQURMT说道:

    The region is divided into eleven administrative districts and the people speak three main local languages namely Wali, Dagaare or Sisali cialis

  5. FSTaPb说道:

    viagra cialis online There were no significant differences between groups in terms of prevalence

  6. Assumpmok说道:

    In compounds of Formula 1, R can be selected from COOH, S O OH, P O OH H, CONHSO CH, CONHSO CF, SO NHCOCH, SO NHCOCH, SO NHCOCF, NHSO CF, NHSO CF, and 1H tetrazol 5 yl, wherein R is selected from C alkyl priligy tablets over the counter Results Nuclei of the epithelial and stromal cells in the vagina and of the stromal cells in the uterus showed strong ER immunostaining on the day of birth day 0, whereas nuclei of the epithelial cells in the uterus exhibited the ER immunostaining by day 5

  7. Assumpmok说道:

    Paraplatin also works by disrupts the growth of cancer cells, which are then destroyed buying viagra cobicistat will increase the level or effect of armodafinil by affecting hepatic intestinal enzyme CYP3A4 metabolism

  8. THATHECOM说道:

    cialis and viagra sales The results of the meta- analysis of FSH are shown in Figure Figure6

  9. grenuenah说道:

    A slick Syriac staffed factory even harvests the produce of Syriac vineyards, making Syriac wines for sale in the restaurants of the new boutique hotels in the historic towns of Mardin and Midyat generic cialis cost Given that previous descriptions of nociceptor structure have not allowed for systematic comparisons between body regions, we sought to use sparse genetic labeling to trace single nociceptor morphologies across the entire somatotopic map

发表回复

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