I do not understand how execlp() works in Linux

后端 未结 2 882
眼角桃花
眼角桃花 2020-11-29 21:57

I have spent the last 2 days trying to understand the execlp() system call, but yet here I am. Let me get straight to the issue.

The man page

2条回答
  •  离开以前
    2020-11-29 22:21

    The limitation of execl is that when executing a shell command or any other script that is not in the current working directory, then we have to pass the full path of the command or the script. Example:

    execl("/bin/ls", "ls", "-la", NULL);
    

    The workaround to passing the full path of the executable is to use the function execlp, that searches for the file (1st argument of execlp) in those directories pointed by PATH:

    execlp("ls", "ls", "-la", NULL);
    

提交回复
热议问题