Next: ����������� �������� ������
Up: �������� ��� ����������� ���������
Previous: ������������� semop
Contents
Index
/* ��������� ������������
����������� ���������� ������ semop()
(�������� ��� ���������� ���������) */
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#define MAXOPSIZE 10
main ()
{
extern int errno;
struct sembuf sops [MAXOPSIZE];
int semid, flags, i, rtrn;
unsigned nsops;
/* ������ ������������� ��������� ��������� */
printf ("\n������� ������������� ��������� ���������,");
printf ("\n��� ������� ����� ����������� ��������: ");
scanf ("%d", &semid);
printf ("\n��-� ��������� ��������� = %d", semid);
/* ������ ����� �������� */
printf ("\n������� ����� �������� ");
printf ("��� ���������� �� ����� ���������: \n");
scanf ("%d", &nsops);
printf ("\n����� �������� = %d", nsops);
/* ���������������� ������ �������� */
for (i = 0; i < nsops; i++) {
/* ������� ������� �� ��������� */
printf ("\n������� ����� ��������: ");
scanf ("%d", &sops [i].sem_num);
printf ("\n����� = %d", sops [i].sem_num);
/* ������ �����, �������� �������� */
printf ("\n������� �������� ��� ���������: ");
scanf ("%d", &sops [i].sem_op);
printf ("\n�������� = %d", sops [i].sem_op);
/* ������� ��������� ����� */
printf ("\n������� ���, ");
printf ("��������������� ��������� ������:\n");
printf (" ��� ������ = 0\n");
printf (" IPC_NOWAIT = 1\n");
printf (" SEM_UNDO = 2\n");
printf (" IPC_NOWAIT � SEM_UNDO = 3\n");
printf (" ����� = ");
scanf ("%d", &flags);
switch (flags) {
case 0:
sops [i].sem_flg = 0;
break;
case 1:
sops [i].sem_flg = IPC_NOWAIT;
break;
case 2:
sops [i].sem_flg = SEM_UNDO;
break;
case 3:
sops [i].sem_flg = IPC_NOWAIT | SEM_UNDO;
break;
}
printf ("\n����� = 0%o", sops [i].sem_flg);
}
/* ����������� ��� ��������� ������� */
printf ("\n������ ��������:\n");
for (i = 0; i < nsops; i++) {
printf (" ����� �������� = %d\n", sops [i].sem_num);
printf (" �������� = %d\n", sops [i].sem_op);
printf (" ����� = 0%o\n", sops [i].sem_flg);
}
/* ��������� ��������� ����� */
rtrn = semop (semid, sops, nsops);
if (rtrn == -1) {
printf ("\nsemop ���������� ��������!\n");
printf ("��� ������ = %d\n", errno);
}
else {
printf ("\nsemop ���������� �������.\n");
printf ("������������� semid = %d\n", semid);
printf ("������������ �������� = %d\n", rtrn);
}
exit (0);
}
Alex Otwagin
2002-12-16
������:
�������: