LCOV - code coverage report
Current view: top level - nrao/VLA - Get_num_attached.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 8 0.0 %
Date: 2024-11-06 17:42:47 Functions: 0 1 0.0 %

          Line data    Source code
       1             : /*
       2             :     Get_num_attached.cc: Find the number of attached processes to a shared
       3             :     memory segment.
       4             :     Copyright (C) 1999
       5             :     Associated Universities, Inc. Washington DC, USA.
       6             : 
       7             :     This library is free software; you can redistribute it and/or modify it
       8             :     under the terms of the GNU Library General Public License as published by
       9             :     the Free Software Foundation; either version 2 of the License, or (at your
      10             :     option) any later version.
      11             : 
      12             :     This library is distributed in the hope that it will be useful, but WITHOUT
      13             :     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14             :     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      15             :     License for more details.
      16             : 
      17             :     You should have received a copy of the GNU Library General Public License
      18             :     along with this library; if not, write to the Free Software Foundation,
      19             :     Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      20             : 
      21             :     Correspondence concerning AIPS++ should be addressed as follows:
      22             :            Internet email: casa-feedback@nrao.edu.
      23             :            Postal address: AIPS++ Project Office
      24             :                            National Radio Astronomy Observatory
      25             :                            520 Edgemont Road
      26             :                            Charlottesville, VA 22903-2475 USA
      27             : 
      28             :     $Id$
      29             : */
      30             : /* Make a call to the system utility shmctl() to determine the number
      31             :  of processes attached to the shared memory segment denoted by the
      32             :  parameter shmid */
      33             : 
      34             : /* If the return value from shmctl is -1, return 0 if errno is EINVAL
      35             :    (shmid is not a valid shared memory id) or -1 other wise. */
      36             : 
      37             : #include <stdio.h>
      38             : #include <sys/types.h>
      39             : #include <sys/ipc.h>
      40             : #include <sys/shm.h>
      41             : #include <errno.h>
      42             : 
      43             : extern int errno;
      44             : 
      45           0 : int Get_num_attached(int shmid) {
      46             : 
      47             :    struct shmid_ds buf;
      48             :    int err;
      49             : 
      50           0 :    if (shmctl(shmid, IPC_STAT, &buf) == 0) {
      51           0 :       return(buf.shm_nattch);
      52             :       }
      53             :    else {
      54           0 :       err = errno;
      55           0 :       perror("error on calling shmctl()");
      56           0 :       if (err == EINVAL) {
      57           0 :          return(0);
      58             :          }
      59             :       else {
      60           0 :          return(-1);
      61             :          }
      62             :       }
      63             :    }

Generated by: LCOV version 1.16