* IPC-Semaphore
@ 2006-05-09 17:06 Christian Stalp
0 siblings, 0 replies; only message in thread
From: Christian Stalp @ 2006-05-09 17:06 UTC (permalink / raw)
To: linux-c-programming
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2006-05-09 17:06 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-05-09 17:06 IPC-Semaphore Christian Stalp
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).