0
#include <stdio.h>
#include <unistd.h>
main() 
{ 

    int some_value;

    printf("Forking process\n");

    fork();

    /* This part of the program is executed by two different proceses */
    printf("The process id is %d \n", getpid());
    some_value = getpid() + 10;
    printf("Some value is %d ", some_value);

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

    /* This line is not executed because of th execl function */
    printf("This line is not printed\n");
}  

For this chunk of code I'm getting the following error:

./fork1.c: line 8: syntax error near unexpected token `"Forking process\n"'
./fork1.c: line 8: ` printf("Forking process\n");'

It doesn't seem to me as a syntax error though.

2
  • 2
    What happens if you do: gcc fork.c && ./a.out ?
    – P.P
    Dec 9, 2014 at 16:52
  • It works just fine! I was trying ./fork.c for some reason :( Dec 9, 2014 at 17:05

1 Answer 1

2

This is not a shell script, it's C.

You have to compile it (e.g.: with gcc) and then run the created executable.

3
  • Sorry about not mentioning that. I have already compiled it with gcc but when I'm trying to run it i'm getting the syntax error. Dec 9, 2014 at 16:53
  • So you're running fork or a.out, not trying to run fork.c?
    – rojomoke
    Dec 10, 2014 at 11:11
  • @GiorgosKaragiannopoulos: clearly you don't, it's visible in the output you've posed: ./fork1.c[...] Dec 10, 2014 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.