execl() arguments in Ubuntu

后端 未结 4 1728
慢半拍i
慢半拍i 2021-01-12 07:42

I am learning linux programming and came across exec function which is kind of very useful. But the problem is exec function arguments are very confusing and I am unable to

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-12 07:45

    The purpose of the ending argument (char *) 0 is to terminate the parameters. Undefined behavior may result if this is missing. The man page defines the execl signature as :

    int execl(const char *path, const char *arg, ...);
    

    path: The location of the program to invoke, the program to invoke.

    arg, ...*: can be thought of as arg0, arg1, ..., argn.

    In your case execl( "/bin/ls", "ls", "-l", (char*)0 ); is the correct function call.

    "bin/ls" the program to invoke

    "ls" the program name

    "-l" is the parameter for that program called

提交回复
热议问题