Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
38
Добавлен:
06.02.2018
Размер:
848 б
Скачать
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/stat.h>
#include <sys/shm.h>
#include <sys/sem.h>

void main()
{
	char *pb, st[81];
	int hmem, hsem;
	struct sembuf sop_lock[1] = {0, -1, 0};
	struct sembuf sop_unlock[1] = {0, 1, 0};
	printf("Begin work 2\n");
	hmem=shmget(1801197, 4000, 0600);
	if (hmem == -1)
	{
		printf("Error Shared Get Mem with\n"); 
		getchar(); 
		exit(0);
	}
	hsem = semget(1801196, 1, 0600);
	if(hsem == -1)
	{
		printf("Error open semaphore:");
		getchar();
		exit(0);
	}
	pb=shmat(hmem, NULL, SHM_RDONLY);
	if (pb == 0)
	{
		printf("Error Attach Shared Mem\n");
		getchar();
		exit(0);
	}
	semop(hsem, &sop_lock[0], 1);
	semop(hsem, &sop_unlock[0], 1);
	strncpy(st, pb, 80);
	st[80]='\0';
	printf("Text: %s\n", st);
	shmdt(pb);
	getchar();
	exit(0);
}
Соседние файлы в папке линукс