programme en C sur les pipes
Bonjour à Tous!!!
Désolé de vous déranger, mais j'aimrais comprendre plus en détail le programme ci dessus!
S'il y a une personne qui peut m'aider, cela serait simpatique de sa part!!!
MERCI ;)
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| #include<stdio.h>
#include<unistd.h>
#define VALUE 100
void output(int p[2]);
void numbers(int p[2]);
int main(void)
{
int channel[2];
pipe (channel1);
if (fork() == 0)
{
numbers(channel1);
}
if (fork() == 0)
{
output(channel1);
}
while (wait((int *)0) >= 0);
}
void output (int p[2])
{
long int num;
while(1)
{
alarm(1);
read(p[0]);
alarm(0);
printf("the number read from the pipe is %d\n", num);
}
}
void numbers(int p[2])
{
long time int num;
int i=0;
srandom((unsigned int) getpid());
while(i < 25)
{
num=random();
if (num % value == 0)
{
write(p[1], &num, sizeof(int));
}
}
} |