Ошибка программы функции fork () при использовании putty [duplicate]

#include<stdio.h>
#include<sys/wait.h>

int main()
{
int p1,p2;
p1=fork();
if(p1==-1)
{
printf(“Error”);
}
else
{
printf(“Parent is %d, Child is %d n”,getppid(),getpid());
}
p2=fork();
printf(“Parent is %d, Child is %d n”,getppid(),getpid());

return 0;

abcd.c: In function ‘main’:
abcd.c:7:4: warning: implicit declaration of function ‘fork’ [-Wimplicit-function-declaration]
 p1=fork();
    ^
abcd.c:10:1: error: stray ‘\342’ in program
 printf(“Error”);
 ^
abcd.c:10:1: error: stray ‘\200’ in program
abcd.c:10:1: error: stray ‘\234’ in program
abcd.c:10:1: error: stray ‘\342’ in program
abcd.c:10:1: error: stray ‘\200’ in program
abcd.c:10:1: error: stray ‘\235’ in program
abcd.c:10:11: error: ‘Error’ undeclared (first use in this function)
 printf(“Error”);
           ^
abcd.c:10:11: note: each undeclared identifier is reported only once for each function it appears in
abcd.c:14:1: error: stray ‘\342’ in program
 printf(“Parent is %d, Child is %d n”,getppid(),getpid());
 ^
abcd.c:14:1: error: stray ‘\200’ in program
abcd.c:14:1: error: stray ‘\234’ in program
abcd.c:14:11: error: ‘Parent’ undeclared (first use in this function)
 printf(“Parent is %d, Child is %d n”,getppid(),getpid());
           ^
abcd.c:14:18: error: expected ‘)’ before ‘is’
 printf(“Parent is %d, Child is %d n”,getppid(),getpid());
                  ^
abcd.c:14:18: error: stray ‘\342’ in program
abcd.c:14:18: error: stray ‘\200’ in program
abcd.c:14:18: error: stray ‘\235’ in program
abcd.c:17:1: error: stray ‘\342’ in program
 printf(“Parent is %d, Child is %d n”,getppid(),getpid());
 ^
abcd.c:17:1: error: stray ‘\200’ in program
abcd.c:17:1: error: stray ‘\234’ in program
abcd.c:17:18: error: expected ‘)’ before ‘is’
 printf(“Parent is %d, Child is %d n”,getppid(),getpid());
                  ^
abcd.c:17:18: error: stray ‘\342’ in program
abcd.c:17:18: error: stray ‘\200’ in program
abcd.c:17:18: error: stray ‘\235’ in program
-2
задан 20 July 2017 в 03:28

1 ответ

Необходимо добавить

#include <unistd.h>

использовать fork, измените все кому: " и добавьте закрытие } в конце:

#include<stdio.h>
#include<sys/wait.h>
#include <unistd.h>

int main()
{
int p1,p2;
p1=fork();
if(p1==-1)
{
printf("Error");
}
else
{
printf("Parent is %d, Child is %d n",getppid(),getpid());
}
p2=fork();
printf("Parent is %d, Child is %d n",getppid(),getpid());

return 0;
}
2
ответ дан 2 November 2019 в 21:46

Другие вопросы по тегам:

Похожие вопросы: