execl function Parameter Problem

Source: Internet
Author: User

function definition:

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

This function is user process operation, Linux is included in header file #include <unistd.h>

Function Description: path represents the file path of the operation, followed by an indeterminate argument list to pass past arguments when the file is executed, and the last parameter needs to be NULL to end.

A classic example:

1 #include <unistd.h>2main ()3{4     execl ("/bin/ls", "LS", "-al", "/etc/passwd", (char *)0); 5 }

However, the second parameter in the example is not passed in the past followed by/bin/ls, but instead overrides the name of the file that was passed in to be executed. But the file name to be executed in the first argument is already very clear, why pass in the second redundant parameter?

According to Apue's explanation: We set the first parameter (Argv[0]) to the filename component of the pathname, and some shells set this parameter to the full pathname, which is just a convention that we can set to any value.

So what is the effect of the second parameter? It will affect the process name and can be verified with ps-ef view.

execl function Parameter Problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.