이 프로그램은 아버지와 2 명의 자녀를 만들 것이며, 체인 문자가있을 것이며, 아버지는 2 개의 파이프를 채우고 첫 번째 숫자는 두 번째 첫 번째 자식은 첫 번째 파이프에서 읽은 다음 두 번째 파이프에서 읽은 다음 두 번째 파이프에서 읽은 문자 수를 반환합니다.프로그램이 실행되지만 전부는 아니며이 오류의 의미를 모르겠 음
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
main()
{
printf("I am the father, I will create 2 sons, the first will read the numbers , the second will read the letters\n");
char *word="alibas123sam";
printf("Now 2 pipes will be created\n");
int fd1[2];
int fd2[2];
pipe(fd1); pipe(fd2);
printf("Now the father will write numbers in the first pipe, and letters in the second\n");
int i;
char numbers[20]; int j=0;
char caracters[20]; int k=0;
for (i=0;i<20;i++)
{
if(word[i]>='0' && word[i]<='9') //if number
{
close(fd1[0]); //closing reading
write(fd1[1],&word[i],1);
}
else
{
close(fd2[0]);
write(fd2[1],&word[i],1);
}
}
printf("The father has wrote in the 2 pipes, now its time for the sons\n");
int f=fork();
if(f==0) //first son
{
for(i=0;i<20;i++) {
close(fd1[1]); //closing writing
read(fd1[0],&numbers[j],1);
j++;
}
printf("first son read everything, he got %d Numbers\n", j);
}
else
{
f=fork();
if(f==0)
{
for(i=0;i<20;i++) {
close(fd2[1]); //closing writing
read(fd2[0],&caracters[k],1);
k++;
}
printf("second son read everything, he got %d caracters\n", k);
}
}}
오류 :
Disallowed system call: SYS_pipe
'pipe (2)'호출의 반환 값을 확인해야합니다. (매우 이상한 이유로) 실패합니다. 이 프로그램을 어디에서 실행하려고합니까? 합리적인 주인인가요? 아니면 어색합니까? 나는 [AppArmor] (http://wiki.ubuntu.com/AppArmor/)와 같은 [필수 액세스 제어] (http://en.wikipedia.org/wiki/Mandatory_access_control) 도구로 제한되는지 궁금합니다.), [SELinux] (http://en.wikipedia.org/wiki/Security-Enhanced_Linux), [TOMOYO] (http://tomoyo.sourceforge.jp/index.html.en) 또는 [SMACK] (http : //schaufler-ca.com/), 그런 _odd_ 오류를 인쇄하는 것은 의심 스럽습니다. – sarnold
왜 설명자를 닫습니까? – ShinTakezou
이게 문제인지 모르겠지만 어쩌면 그걸 닫지 말아야지 * 포크 전에, 할 수있어 * 후에 * 갈래, 만약 당신이 그들을 필요로하지 않는다면 – ShinTakezou