意外令牌fork()附近的语法错误

时间:2014-12-09 16:46:09

标签: c shell ubuntu-14.04

#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");
}  

对于这段代码,我收到以下错误:

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

虽然我觉得这不是一个语法错误。

1 个答案:

答案 0 :(得分:2)

这不是一个shell脚本,它是C。

你必须编译它(例如:用gcc)然后运行创建的可执行文件。