Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
4
Добавлен:
26.05.2014
Размер:
806 б
Скачать
#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");
}
Соседние файлы в папке lab41
  • #
    26.05.20141.16 Кб4barb.c
  • #
    26.05.201412.13 Кб4barber
  • #
    26.05.201412.77 Кб4barber.out
  • #
    26.05.2014806 б4cl.c
  • #
    26.05.201412.42 Кб4cl.out
  • #
    26.05.201411.74 Кб4client
  • #
    26.05.201424 б4q.sh
  • #
    26.05.201418 б4q2.sh