Tuesday, 15 April 2014

c - using the command gcc with execlp -



c - using the command gcc with execlp -

i have problem while utilize gcc execlp. here result of execution

root@ubuntu:~/sys/tp# ./sys shoum.c: fatal error: no input files compilation terminated. done2 my code #include <stdio.h> #include <stdlib.h> #include <unistd.h> /* fork */ #include <sys/types.h> /* pid_t */ #include <sys/wait.h> /* wait */ int main(int argc,char** argv) { /*spawn kid run program.*/ pid_t pid=fork(); if (pid==0) { /* kid process */ execlp("gcc","shoum.c",null); // execlp("ls","-liha",null); printf("not working\n"); exit(127); /* if execv fails */ } else { /* pid!=0; parent process */ waitpid(pid,0,0); /* wait kid exit */ printf("done2 \n"); } homecoming 0; }

ps: when utilize other commands ls or cat execlp works doesn't gcc.

you're missing argument, should be:

execlp("gcc", "gcc", "shoum.c", (char*)null);

the first argument programme run, remaining arguments argv[] array program. missing argv[0], contains name of programme beingness run. gcc thought beingness run name shoum.c , no filename parameters.

c linux gcc fork

No comments:

Post a Comment