궁금하네요. 그러나 주어진 waitpid()
경우에만 시도하고 인쇄 할 때 정수를 받아들이 나 0 제공합니다.이 문제를 해결하는 방법 또는이 경우에도 문제가있는 경우.변경 매개 변수()
계산 모양을 의미한다 (1+ (2 × 3)/(2 × 7)) = 0.5
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(){
int a = 1, b = 2, c = 3, d = 2, e = 7;
int a_plus_pid, b_times_c_pid, d_times_e_pid;
int a_plus, b_times_c, d_times_e;
a_plus_pid = fork();
if(a_plus_pid)
{
b_times_c_pid = fork();
if(b_times_c_pid)
{
d_times_e_pid = fork();
if(d_times_e_pid)
{
waitpid(a_plus_pid, &a_plus, 0);
waitpid(b_times_c_pid, &b_times_c, 0);
waitpid(d_times_e_pid, &d_times_e, 0);
//Supposed to print 0.50
printf("%d" , ((a + (b_times_c)))/d_times_e);
}
else
{
exit(d*e);
}
}
else
{
exit(b*c);
}
}
else
{
exit(a);
}
}
http://advancedlinuxprogramming.com/을 읽고 기사를 읽는데 며칠을 보내십시오 ([waitpid (2)] (http://man7.org/linux/man-pages/man2/waitpid.2.html) , [pipe (7)] (http://man7.org/linux/man-pages/man2/fork.2.html) pages/man7/pipe.7.html), [execve (2)] (http://man7.org/linux/man-pages/man2/waitpid.2.html), [popen (3)] (http : //man7.org/linux/man-pages/man3/popen.3.html) ..). 귀하의 질문은 심오한 오해를 보여 주며 많은 의미가 없습니다. [Operating Systems] (http://pages.cs.wisc.edu/~remzi/OSTEP/)에 대해서도 읽어보십시오. –
산술 연산은 모두 정수 연산입니다. 당신은 그것으로부터 부동 소수점 값을 결코 얻지 못할 것입니다. 종료 코드는 255 자로 제한됩니다. 문제가 발생할 수도 있습니다. else 체인에 중첩 된 if는 서툴러 보인다. 포크 (자식)의 반환 값 0을 포크 팅하고 테스트하는 것이 더 좋을 것입니다. 그리고 다음 자식을 분기하는 다른 작업을 수행하는 것이 좋습니다. –
그래, 내 문제는 내가 부동 소수점 반환이 필요합니다. waitpid 작업을 호출 한 후 캐스팅됩니다 궁금해? – Dreeww