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

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

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

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

        /* ��������� ������������
           ����������� ���������� ������ shmctl()
           (�������� ���������� ������������ ����������) */

        #include <stdio.h>
        #include <sys/types.h>
        #include <sys/ipc.h>
        #include <sys/shm.h>

        main ()
        {
          extern int errno;
          int rtrn, shmid, command, choice;
          struct shmid_ds shmid_ds, *buf;
          buf = &shmid_ds;

          /* ������ ������������� �������� � �������� */
          printf ("������� ������������� shmid: ");
          scanf ("%d", &shmid);

          printf ("������� ����� ���������� ��������:\n");
          printf ("  IPC_STAT   = 1\n");
          printf ("  IPC_SET    = 2\n");
          printf ("  IPC_RMID   = 3\n");
          printf ("  SHM_LOCK   = 4\n");
          printf ("  SHM_UNLOCK = 5\n");
          printf ("  �����      = ");
          scanf ("%d", &command);

          /* ��������� �������� */
          printf ("\n������������� = %d, �������� = %d\n",
                  shmid, command);

          switch (command) {
            case 1:     /* ����������� ����������
                           � ��������� ������������ ��������
                           � ���������������� ���������
                           � ������� �� */

              rtrn = shmctl (shmid, IPC_STAT, buf);
              printf ("\n��-� ������������ = %d\n",
                      buf->shm_perm.uid);
              printf ("��-� ������ ������������ = %d\n",
                      buf->shm_perm.gid);
              printf ("��-� ��������� = %d\n",
                      buf->shm_perm.cuid);
              printf ("��-� ������ ��������� = %d\n",
                      buf->shm_perm.cgid);
              printf ("����� �� �������� = 0%o\n",
                      buf->shm_perm.mode);
              printf ("������������������ ������� ");
                      buf->shm_perm.cgid);
              printf ("������������ ������ = 0%x\n",
                      buf->shm_perm.seq);
              printf ("���� = 0%x\n", buf->shm_perm.key);
              printf ("������ �������� = %d\n", buf->shm_segsz);
              printf ("�������� ��������� �������� = %d\n",
                      buf->shm_lpid);
              printf ("������ ������� = %d\n", buf->shm_cpid);
              printf ("����� �������������� ������� = %d\n",
                      buf->shm_nattch);
              printf ("����� ������������ � ������ = %d\n",
                      buf->shm_cnattch);
              printf ("��������� ������������� = %d\n",
                      buf->shm_atime);
              printf ("��������� ������������ = %d\n",
                       buf->shm_dtime);
              printf ("��������� ��������� = %d\n",
                       buf->shm_ctime);
              break;

            case 2:     /* ������� � �������� ���� (����)
                           ��������������� ��������� ������ */
              /* �������� �������� �������� ��������� ������ */
              rtrn = shmctl (shmid, IPC_STAT, buf);
              printf ("������� ����� ����������� ����:\n");
              printf ("  shm_perm.uid  = 1\n");
              printf ("  shm_perm.gid  = 2\n");
              printf ("  shm_perm.mode = 3\n");
              printf ("  �����         = ");
              scanf ("%d", &choice);

              switch (choice) {
                case 1:
                  printf ("\n������� ��-� ������������: "),
                  scanf ("%d", &buf->shm_perm.uid);
                  printf ("\n��-� ������������ = %d\n",
                          buf->shm_perm.uid);
                  break;

                case 2:
                  printf ("\n������� ��-� ������: "),
                  scanf ("%d", &buf->shm_perm.gid);
                  printf ("\n��-� ������ = %d\n",
                          buf->shm_perm.uid);
                  break;

                case 3:
                  printf ("\n������� ������������ ��� ����: ");
                  scanf ("%o", &buf->shm_perm.mode);
                  printf ("\n����� �� �������� = 0%o\n",
                          buf->shm_perm.mode);
                  break;
              }

             /* ������ ��������� */
             rtrn = shmctl (shmid, IPC_SET, buf);
             break;

          case 3:      /* ������� ������������� �
                          ��������������� ��������� ������ */
            rtrn = shmctl (shmid, IPC_RMID, NULL);
            break;


          case 4:     /* ���������� ����������� �������
                         � ������ */
            rtrn = shmctl (shmid, SHM_LOCK, NULL);
            break;

          case 5:    /* ��������� ���������� ������� � ������ */
            rtrn = shmctl (shmid, SHM_UNLOCK, NULL);
        }

        if (rtrn == -1) {
          /* �������� � ��������� ���������� */
          printf ("\nshmctl ���������� ��������!\n");
          printf ("\n��� ������ = %d\n", errno);
        }
        else {
          /* ��� �������� ���������� �������� ��-� shmid */
          printf ("\nshmctl ���������� �������, ");
          printf ("������������� shmid = %d\n", shmid);
        }

        exit (0);
      }



Alex Otwagin 2002-12-16



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

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