How does execlp work, what's the last NULL argument?



  • #include <stdio.h>
    
    main(){
     printf("Poczatek\n");
     // что за последний аргумент, я читал, что это
     // какой-то указатель, никак к сожалению понять не могу. 
     execlp("ls", "ls", "-a", NULL); 
     printf("Koniec\n");
    }
    


  • I read that it's some kind of index, but I can't understand.

    Let's try reading. http://www.opennet.ru/man.shtml?category=3&russian=0&topic=execlp together:

    int execlp(const char *file, const char *arg, ...); 
    

    Parameter const char *arg and similar entries in execl functions, execlp, and execle imply parameters arg0, arg1, ..., argn. All together, they describe one or more line markers, end of NULL, which is a list of parameters, available program. First parameter, by agreement, should indicate in the name associated with the file that needs to be Do it. The list of parameters should end with NULL.

    Call attention to the last sentence. It means that NULL is used to indicate the end of the list of arguments. It's one of the general mechanisms to say "more accumulations aren't available" in challenging functions with a variable number of arguments.


    By the way, you realize that with a successful launch. ls You'll never get here?

    printf("Koniec\n");
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2