Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
5
Добавлен:
26.05.2014
Размер:
777 б
Скачать
#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);

//msg struct
typedef struct msgbf
{
long mtype;
char buf;
} message;

message mes;
int	key,msg;
int	m;
char	ch;

int main(int argc,char *argv[])
{

mes.mtype=123;
key=ftok("tst",'c');
if ((msg=msgget(key,0))<0)
{printf("I can't connect to message\'s queue");
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(msg,(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(msg,IPC_RMID,0);
printf("All client's gone \n");
}
Соседние файлы в папке 4
  • #
    26.05.20141.33 Кб5barb.c
  • #
    26.05.201412.13 Кб5barber
  • #
    26.05.2014777 б5cl.c
  • #
    26.05.201411.74 Кб5client
  • #
    26.05.2014212 б5Makefile