.MESAJE

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


^#include <sys/types.h>
^#include <sys/ipc.h>
^#include <sys/msg.h>
^int msqid;
^struct msqid_ds buf;
^struct msgform
{
^long mtype;
^char mtext[256];
}
msg;
^int life=64;
^main()
{
^pid_t pid;
^msqid= msgget(IPC_PRIVATE, IPC_CREAT | 0644);
^if(msqid== -1){
^printf("Nu se mai poate aloca o noua coada de mesaje!
");
^exit(-1);
}
^printf("msqid= [procent]d ", msqid);
^msgctl(msqid, IPC_STAT, [and]buf);
^printf("msg_qbytes= [procent]d ", buf.msg_qbytes);
^printf("msg_qnum= [procent]d ", buf.msg_qnum);
^printf("msg_cbytes= [procent]d
", buf.msg_cbytes);
^if (fork()== 0)
{
//proces consumator
^while(life--)
{
^if(msgrcv(msqid, [and]msg, 256, 17, !IPC_NOWAIT)== -1)
^perror("msgrcv()");
^else
^printf(">> C[procent]d:[procent]c
", life, msg.mtext[0]);
}
^exit(0);
}
^else
{
//proces producator
^while(life--)
{
^msg.mtype=17;
^msg.mtext[0]=life[procent]2==0?'#':'*';
^printf("<< P[procent]d:[procent]c
",life, msg.mtext[0]);
^if(msgsnd(msqid, [and]msg, 256, IPC_NOWAIT)== -1)
^perror("msgsnd()");
}
^do
{
^msgctl(msqid, IPC_STAT, [and]buf);
}
^while(buf.msg_qnum!=0);
^msgctl(msqid, IPC_RMID, (struct msqid_ds *) 0);
^exit(0);
}
}