linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Stalp <stalp@imbei.uni-mainz.de>
To: linux-c-programming@vger.kernel.org
Subject: IPC-Semaphore
Date: Tue, 9 May 2006 19:06:43 +0200	[thread overview]
Message-ID: <200605091906.43370.stalp@imbei.uni-mainz.de> (raw)

Hello out there,
Im working on a solution to delete a semaphore, which is used by other 
processes.
The semaphore was created by a server-process. It write the semaphore-key into 
a file ( where the clients can read it, and get access to the semaphore )
After that the server proceeds its work. 
When the server finished its work, it destroys the semaphore. And here we have 
quandary. In this very moment the clients still need the semaphore.

In the semctl-manual we have a several arguments, amongst others.
GETZCNT     The  system  call returns the value of semzcnt for the sem-
                   num-th semaphore of the set (i.e. the number  of  processes
                   waiting for semval of the semnum-th semaphore of the set to
                   become 0).  The calling process must have read access priv-
                   ileges on the semaphore set.
or
GETNCNT     The  system  call returns the value of semncnt for the sem-
                   num-th semaphore of the set (i.e. the number  of  processes
                   waiting  for  an  increase  of  semval  for  the  semnum-th
                   semaphore of the set).  The calling process must have  read
                   access privileges on the semaphore set.

based on this I made this function:
/* Loeschen einer Semaphore                                               */
int loesche_semaphore ( int kennung )
{
  union semun mysem;
  int semnum      = 0,
      rueckgabe_1 = 0,
      rueckgabe_2 = 0;

  while ( 1 )
  {
     if ( ( rueckgabe_1 = semctl ( kennung, semnum, GETZCNT, mysem ) ) == -1 )
     {
         perror ( "Fehler beim bestimmen der Semaphor-Wartelist\n" );
         exit ( errno );
     }
     else if ( ( rueckgabe_2 = semctl ( kennung, semnum, GETNCNT, mysem ) ) == 
-1 )
     {
         perror ( "Fehler beim bestimmen der Semaphor-Wartelist\n" );
         exit ( errno );
     }
     else
     {
         printf ( "Die Menge der Prozesse ist gleich: %d und %d \n", 
rueckgabe_1, rueckgabe_2 );
         break;
     }
  }

  if ( ( semctl ( kennung, 0, IPC_RMID, mysem ) ) == -1 )
  {
      perror ( "Fehler beim loeschen der Semaphore\n" );
      exit ( errno );
  }

 return ( 1 );
}

I know that so far this function doesn't work. It should only show me if some 
process try to access the semaphore. 
But neither GETZCNT nor GETNCNT give me info about processes which try to 
access the semaphore. Both gave me a '0'

What is the problem, what I have missed?

Thank you all...

Gruss Christian

-- 
Christian Stalp
Institut für Medizinische Biometrie, Epidemiologie und Informatik
Johannes-Gutenberg-Universität Mainz
Tel.: 06131 / 17-3107
E-Mail: stalp@imbei.uni-mainz.de
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

                 reply	other threads:[~2006-05-09 17:06 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200605091906.43370.stalp@imbei.uni-mainz.de \
    --to=stalp@imbei.uni-mainz.de \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).