home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / slackwar / a / util / util-lin.2 / util-lin / util-linux-2.2 / sys-utils / ipcrm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-22  |  814 b   |  51 lines

  1. /*
  2.  * krishna balasubramanian 1993
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <errno.h>
  8. #include <sys/shm.h>
  9. #include <sys/msg.h>
  10. #include <sys/sem.h>
  11.  
  12. int main(int argc, char **argv)
  13. {
  14.     int id;
  15.     union semun arg;
  16.  
  17.     arg.val = 0; 
  18.  
  19.     if (argc != 3 || strlen(argv[1]) < 3) {
  20.         printf ("usage: %s [shm | msg | sem] id\n", argv[0]);
  21.         exit (1);
  22.     }
  23.     id = atoi (argv[2]);
  24.     switch (argv[1][1])  {
  25.     case 'h':
  26.         if (!shmctl (id, IPC_RMID, NULL)) 
  27.         break;
  28.         perror ("shmctl "); 
  29.         exit (1);
  30.         
  31.     case 'e':
  32.         if (!semctl (id, 0, IPC_RMID, arg)) 
  33.         break;
  34.         perror ("semctl "); 
  35.         exit (1);
  36.  
  37.     case 's':
  38.         if (!msgctl (id, IPC_RMID, NULL)) 
  39.         break;
  40.         perror ("msgctl "); 
  41.         exit (1);
  42.  
  43.     default:
  44.         printf ("usage: %s [-shm | -msg | -sem] id\n", argv[0]);
  45.         exit (1);
  46.     }
  47.     printf ("resource deleted\n");
  48.     return 0;
  49. }
  50.             
  51.