,SEMNALE

Сделай свою wap-шпаргалку =) попробуй конструктор сайтов http://www.panweb.com/


^#include <stdio.h>
^#include <stdlib.h>
^#include <signal.h>
^#define TRUE 1
^#define FALSE 0
^int produce=FALSE;
^int consuma=FALSE;
^void intSIGALRM()
{
^produce=TRUE;
}
^void intSIGTERM()
{
^consuma=TRUE;
}
^int main()
{
^unsigned char articol;
^int life=10;
^int pid1, pid2;
^int fildes[2];
^signal(SIGALRM, intSIGALRM);
^signal(SIGTERM, intSIGTERM);
^pipe(fildes);
^if((pid1=fork())==0){
// proces producator
^close(fildes[0]);
^while(life--){
^while (produce==FALSE);
^articol=(unsigned char)rand();
^write(fildes[1],[and]articol,sizeof(articol));
^printf("
P[procent]d:[procent]02X >> ", life, articol);
^fflush(stdout);
^produce=FALSE;
^signal(SIGALRM, intSIGALRM);
^signal(SIGTERM, SIG_IGN);
^kill(0, SIGTERM);
}
^exit(0);
}
^if((pid2=fork())==0){
// proces consumator
^close(fildes[1]);
^while(life--)
{
^while (consuma==FALSE);
^read(fildes[0],[and]articol,sizeof(articol));
^printf("C[procent]d:[procent]02X", life, articol);
^fflush(stdout);
^consuma=FALSE;
^signal(SIGTERM, intSIGTERM);
^signal(SIGALRM, SIG_IGN);
^kill(0, SIGALRM);
}
exit(0);
}
// proces coordonator
^kill(pid1,SIGALRM);
^return 0;
}