�������: ������ (���� | �����������) ��RU opennet.me  
The OpenNET Project / Index page

[ ������� /+++ | ����� | ���� | ]

������� ������������ / ������ "������������ ��� Linux" / ���������� ���������
next up previous contents index
Next: �������� ��� ��������� ��������� Up: ���������� ��������� ��������� Previous: ������������� msgctl   Contents   Index

���������-������

���������� ����������, ��������� � ���������:

command

��� ������������ ��������.

choice

������������ ��� ������ ���� ��������������� ��������� ������, ������� ����� ��������.

msqid_ds

��������� ��� �������� ���������� �� �������.

��������� ����� ���� ��������� �������. ������ ����� ������������ ������ ���������� ������������� ������� ���������, ������� ��������� � ���������� msqid (������ 15, 16). ��� �������� ��������� � ������ ��������� ������ msgctl.

����� ����� ������ ��� ���������� ������������ �������� (������ 17-22); �� ��������� � ���������� command.

���� ������� �������� IPC_STAT (��� 1), ��������� ����� ����������� (������ 31) � ��������������� ���������� � ��������� ������� (������ 32-39); � ��������� ��������������� ������ �� ���� ���������, ������� ����� ���� ���������������. �������, ��� ���� ��������� ����� ����������� ��������, ��������������� ���������� � ��������� ������� �� ������ ���������� ��������� ���������� ���������� ������. ����� ����, ��������� ��������� �� ������ � ��������������� �������� ���������� errno (������ 90, 91). ���� ��������� ����� ����������� �������, ��������� ���������, ������������ �� ����, � �������� ��������������� �������������� ������� ��������� (������ 95, 96).

���� ������� �������� IPC_SET (��� 2), ��������� ������ ����� �������� ���������� � ������� ��������� ������� ��������� � �������� ��������������� (������ 45). ��� ����������, ��������� ������ ������������ ��������� ������ ������ ���� �� ���� ���, � �� ����� ��� ��������� ����� �������� ��� ��������� �������. ����� ����, ���� � ���� �� ����� ���������, ����������� � ��- ����� ������ ������������, ����� �������� ������������ ��������, ��� ����� ������� ������� � ���������� ����������� ��������, ������������� �� ��� ���, ���� �������� ���� �� ����� ����������. ����� ��������� ���������� ������ ���, ��������������� ���� ���������, ������� ������ ���� �������� (������ 46-53). ���� ��� ��������� � ���������� choice. �����, � ����������� �� ���������� ����, ��������� ���������� ������ �� ��� ���� ����� �������� (������ 54-79). �������� ��������� � ��������������� ���� ��������� ������, ������������� � ������� ������ ������������, � ����������� ��������� ����� (������ 81).

���� ������� �������� IPC_RMID (��� 3), ����������� ��������� ����� (������ 86), ��������� �� ������� ������������� msqid, ������� ��������� � ��������������� � ��� ��������� ������. �������, ��� ��� ���������� ����� ������������ �������� �������� buf �� ���������, ������� ��� �������� ����� ���� �������� ����� (NULL).

      1 /* ��������� ������������
      2    ����������� ���������� ������ msgctl()
      3    (���������� ��������� ���������) */

      4 #include <stdio.h>
      5 #include <sys/types.h>
      6 #include <sys/ipc.h>
      7 #include <sys/msg.h>

      8 main ()
      9 {
     10   extern int errno;
     11   int msqid, command, choice, rtrn;
     12   struct msqid_ds msqid_ds, *buf;
     13   buf = &msqid_ds;

     14   /* ������ ������������� � �������� */
     15   printf ("������� ������������� msqid: ");
     16   scanf ("%d", &msqid);

     17   printf ("������� ����� ���������� ��������:\n");
     18   printf ("  IPC_STAT = 1\n");
     19   printf ("  IPC_SET  = 2\n");
     20   printf ("  IPC_RMID = 3\n");
     21   printf ("  �����    = ");
     22   scanf ("%d", &command);

     23   /* ��������� �������� */
     24   printf ("������������� = %d, �������� = %d\n",
     25           msqid, command);

     26   switch (command) {
     27     case 1: /* ����������� ����������
     28                � ��������� ������� ���������
     29                � ���������������� ���������
     30                � ������� �� */
     31       rtrn = msgctl (msqid, IPC_STAT, buf);
     32       printf ("\n ������������� ������������ = %d\n",
     33               buf->msg_perm.uid);
     34       printf ("\n ������������� ������ = %d\n",
     35               buf->msg_perm.gid);
     36       printf ("\n ����� �� �������� = 0%o\n",
     37               buf->msg_perm.mode);
     38       printf ("\n ������ ������� � ������ = %d\n",
     39               buf->msg_qbytes);
     40       break;

     41     case 2: /* ������� � �������� ���� (����)
     42                 ��������������� ��������� ������ */
     43       /* ������� �������� �������� ��������
     44          ��������� ������ */
     45       rtrn = msgctl (msqid, IPC_STAT, buf);
     46       printf ("\n������� ����� ����, ");
     47       printf ("������� ����� ��������:\n");
     48       printf ("  msg_perm.uid  = 1\n");
     49       printf ("  msg_perm.gid  = 2\n");
     50       printf ("  msg_perm.mode = 3\n");
     51       printf ("  msg_qbytes    = 4\n");
     52       printf ("  �����         = ");
     53       scanf ("%d", &choice);

     54       switch (choice) {
     55         case 1:
     56           printf ("\n������� ��-� ������������: ");
     57           scanf ("%d", &buf->msg_perm.uid);
     58           printf ("\n��-� ������������ = %d\n",
     59                   buf->msg_perm.uid);
     60           break;
     61         case 2:
     62           printf ("\n������� ��-� ������: ");
     63           scanf ("%d", &buf->msg_perm.gid);
     64           printf ("\n��-� ������ = %d\n",
     65                   buf->msg_perm.uid);
     66           break;

     67         case 3:
     68           printf ("\n������� ������������ ��� ����: ");
     69           scanf ("%o", &buf->msg_perm.mode);
     70           printf ("\n����� �� �������� = 0%o\n",
     71                   buf->msg_perm.mode);
     72           break;

     73         case 4:
     74           printf ("\n������� ������ ������� = ");
     75           scanf ("%d", &buf->msg_qbytes);
     76           printf ("\n����� ���� � ������� = %d\n",
     77                   buf->msg_qbytes);
     78           break;
     79       }

     80       /* ������ ��������� */
     81       rtrn = msgctl (msqid, IPC_SET, buf);
     82       break;

     83    case 3: /* ������� ������������� �
     84               ��������������� � ��� �������
     85               ��������� � ��������� ������ */
     86      rtrn = msgctl (msqid, IPC_RMID, NULL);
     87   }

     88   if (rtrn == -1) {
     89     /* �������� � ��������� ���������� */
     90     printf ("\nmsgctl ���������� ��������!\n");
     91     printf ("\n��� ������ = %d\n", errno);
     92   }

     93   else {
     94     /* ��� �������� ���������� �������� msqid */
     95     printf ("\nmsgctl ���������� �������,\n");
     96     printf ("������������� = %d\n", msqid);
     97   }

     98   exit (0);
     99 }



Alex Otwagin 2002-12-16



������:
PostgresPro
Inferno Solutions
Hosting by Hoster.ru
�������:

�������� �� �����
���������� �� ���������
Created 1996-2026 by Maxim Chirkov
��������, ����������, ����������