Operating System - HP-UX
1833924 Members
3092 Online
110063 Solutions
New Discussion

Semaphores, Using Files and process control

 
John J Archer
Occasional Contributor

Semaphores, Using Files and process control

Since my thread on using multiple SYSLOGD processes is not going any where, I have the following situation. I have an application that has at least 6 concurrently executing programs that all write entries to a log file for that one instance (I can have 100 such instances running at the same time). In the current programming, the 6 processes execute a function called LOG_ERR that does a semop to get exclusive access to the common instance log file, opens, writes and closes the log file and finally does a semop to release exclusive access to the log file. The problem I have is that some of these processes are in the middle of a LOG_ERR and a signal is received that causes the same process to need to write another log entry but gets caught up in the queue of processes waiting on the semophore (for exclusive access) to be released. My question is this: How do I determine the current process that has control of the semophore? My logic is, if the process that has the current semaphore control (lock) is needing to make another entry (because of a interrupt) then that process does not need to lock again, just write.
1 REPLY 1
A. Clay Stephenson
Acclaimed Contributor

Re: Semaphores, Using Files and process control

A semctl can use GETPID to get the PID of the last operation but sema4's for your application seems a little inappropriate since lockf() or fcntl() with a F_SETLKW command should be a perfect fit.
If it ain't broke, I can fix that.