09-17-2009
Suggestion:
Create a named semaphore with sem_open. This has one disadvantage - if the program crashes the semaphore persists. If you perceive this as a problem for you then
create a program special option (like -f) to force the program to call sem_unlink() before it does anything else. The option is not provided under normal operation.
1. sem_open() - then check the semaphore setting to see if it is less than the maximum limit you want to impose.
2. if it is at max, then exit, (Windows does something like this) else increment the sempahore.
3. register an atexit function:
decrement the semaphore
if the semaphore is now zero, call sym_unlink()
4. run the rest of your code
5. exit (#3 handles the sempahore for you.)
10 More Discussions You Might Find Interesting
1. UNIX for Advanced & Expert Users
I would like to start up multiple instances of syslog daemon. I am having a little difficulty. Is this at all possible?
I have separate syslog.conf1.... syslog.conf5 files.
I have linked the daemon to separate files syslogd1 ... syslogd5
I have arranged the rcd.2 start/stop scripts for... (9 Replies)
Discussion started by: Gary Dunn
9 Replies
2. UNIX for Dummies Questions & Answers
I am capturing text based reports with a specific program, which works no problem. However, since I send report warehouse output as they are migrated from the database software, on occasion when two capture process' initiate simultaneously, the capture file locks up. Is there a way to setup (in... (1 Reply)
Discussion started by: gozer13
1 Replies
3. Shell Programming and Scripting
set -A arr a1 a2 a3 a4
# START
ssh -xq $Server1 -l $Username /usr/bin/ksh <<-EOS
integer j=0
for loop in ${arr}
do
printf "array - ${arr}\n"
(( j = j + 1 ))
j=`expr j+1`
done
EOS
# END
=========
this is not giving me correct output.
I... (5 Replies)
Discussion started by: reldb
5 Replies
4. Shell Programming and Scripting
Hi Gurus
I have a requirement like this. i use solaris OS..
if there are 2 instances of the same ksh file running in the directory, i need to kill the ksh file that started to run latest.
suppose ragha.ksh starts running thru cron in abc/xyz directory
now ragha.ksh started running by any... (3 Replies)
Discussion started by: ragha81
3 Replies
5. Solaris
I have built this Solaris 10 server, uses NIS. When the server starts up, two instances of ypbind start. This prevents the server from binding to any domain. The SMF in turn prevents any other network services (sshd and the like) from starting up.
Has anyone seen this problem before? (0 Replies)
Discussion started by: blowtorch
0 Replies
6. Shell Programming and Scripting
Could you please let me know how to create/make a multiple instances of a job/process in ksh(shell scripting).
i.e., at present the parent script is calling another child/dependent script for only once.
What we want is, the parent script itself has to execute multiple times, and in each one it... (1 Reply)
Discussion started by: Gangegowda
1 Replies
7. Programming
Hello. This shouldn't be an unusual problem, but I cannot find anything about it at google or at other search machine.
So, I've made an application using C++ and QtCreator. I 've made a new mime type for application's project files.
My system (ubuntu 10.10), when I right click a file and I... (3 Replies)
Discussion started by: hakermania
3 Replies
8. Programming
Suppose I declare
pthread_t clear_thread;
and then
pthread_create(&clear_thread, &detach, clear_message, this);
the thread is supposed to go away, perform the service it is intended to procide, and then kill itself.
A little while later, I require this service again, so I say
... (2 Replies)
Discussion started by: clerew
2 Replies
9. Shell Programming and Scripting
I would like to execute a commands in four different servers through ssh at a single instance(simultaneously).
Below are the details with examples,
ssh user1@server1 "grep xxxx logs"
ssh user1@server2 "grep xxxx logs"
ssh user1@server3 "grep xxxx logs"
Each statement will take some... (4 Replies)
Discussion started by: Amutha
4 Replies
10. UNIX for Beginners Questions & Answers
I have a db server with two instances...trying to create an expect script that will scan both the listener and the alert log files and retrieve their sizes.
Issue we have is that the .profile is hard coded with one of the databases name and script is always pulling from the same instance (testdb1)... (1 Reply)
Discussion started by: donpasscal
1 Replies
LEARN ABOUT OPENSOLARIS
sem_close
sem_close(3C) Standard C Library Functions sem_close(3C)
NAME
sem_close - close a named semaphore
SYNOPSIS
#include <semaphore.h>
int sem_close(sem_t *sem);
DESCRIPTION
The sem_close() function is used to indicate that the calling process is finished using the named semaphore indicated by sem. The effects
of calling sem_close() for an unnamed semaphore (one created by sem_init(3C)) are undefined. The sem_close() function deallocates (that is,
make available for reuse by a subsequent sem_open(3C) by this process) any system resources allocated by the system for use by this process
for this semaphore. The effect of subsequent use of the semaphore indicated by sem by this process is undefined. If the semaphore has not
been removed with a successful call to sem_unlink(3C), then sem_close() has no effect on the state of the semaphore. If the sem_unlink(3C)
function has been successfully invoked for name after the most recent call to sem_open(3C) with O_CREAT for this semaphore, then when all
processes that have opened the semaphore close it, the semaphore is no longer be accessible.
RETURN VALUES
If successful, sem_close() returns 0, otherwise it returns -1 and sets errno to indicate the error.
ERRORS
The sem_close() function will fail if:
EINVAL The sem argument is not a valid semaphore descriptor.
ENOSYS The sem_close() function is not supported by the system.
USAGE
The sem_close() function should not be called for an unnamed semaphore initialized by sem_init(3C).
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
|ATTRIBUTE TYPE |ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Committed |
+-----------------------------+-----------------------------+
|MT-Level |MT-Safe |
+-----------------------------+-----------------------------+
|Standard |See standards(5). |
+-----------------------------+-----------------------------+
SEE ALSO
sem_init(3C), sem_open(3C), sem_unlink(3C), attributes(5), standards(5)
NOTES
Solaris 2.6 was the first release to support the Asynchronous Input and Output option. Prior to this release, this function always returned
-1 and set errno to ENOSYS.
SunOS 5.11 5 Feb 2008 sem_close(3C)