Teodora kulikov Teodora kulikov - 2 months ago 5x
C Question

Proper use of execl in linux

I want to run file test2.c from the file test1.c .But it is not happening so?Any mistake?

int main(){
int j=execl("/home/ishan/os","test2.c",(char*)NULL);


You are passing in the arguments incorrectly.

Assuming that your executable image is called "test2", try this:

    int j=execl("/home/ishan/os/test2", "/home/ishan/os/test2", (char*)NULL);


  • The first argument is the complete path to the target executable, including the filename.
  • The second argument is passed as argv[0] to the new process. Conventionally, this is also the complete path to the target executable.
  • The target executable is not the source code file ("test2.c"), but the result of compiling that source code (typically, "test2").

Reference: http://linux.die.net/man/3/execl