Добавил:
Fragga
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:лабораторки по ОС препод Челноков / 2семестр / wi2 / zubanov / lab41 / cl
.c#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
static int ctrl_c(int);
typedef struct msgbuf
{
long mtype;
char buf;
} message;
message mes;
key_t key;
int msgid;
int n;
char ch;
int main(int argc,char *argv[])
{
mes.mtype=1L;
if ( (key=ftok("barb",'c'))<0){ printf("key error\n");exit(1); } ;
if ((msgid=msgget(key,0))<0)
{printf("queue rror\n ");
exit(1);}
if (argc==2)
{printf("%s client\n",argv[1]);
mes.buf=*argv[1];}
else
{printf("1 client\n");
mes.buf=1;}
if (msgsnd(msgid,(void *)&mes,1,0)!=0)
{printf("I can\'t send message");}
return 0;
}
static int ctrl_c(int sig)
{
signal(SIGINT,(void *)&ctrl_c);
msgctl(msgid,IPC_RMID,0);
printf("All clients went out \n");
}