This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Linux / UNIX and the fly likes flock in Solaris Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » Linux / UNIX
Reply Bookmark "flock in Solaris" Watch "flock in Solaris" New topic
Author

flock in Solaris

Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
In Linux systems there is a flock command that is used to create a lock file so that processes can synchronize execution of some protected resource. I understand that Solaris systems don't support this. Is there some other equivalent command that functions similar to flock?

My shell programming is very rusty...coming back slowly.

I am developing a prototype using cygwin with Windows XP.

I have a master shell which starts 5 processes in the background. I need someway to have the processes communicate with each other, i.e. some sort of shared memory or lock file (semaphore).

I export environmental variables and the sub processes can read them but when they change them the other processes don't get the change as they have their own address space (and are not part of the parent-child relationship.)

Any help is greatly appreciated.
[ July 23, 2008: Message edited by: James Clark ]
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4422
    
    2

Are you sure you want to do this? file locking is actually a very complex topic, espcially if any of the files can be on network structures such as NFS or SMB. Its really hard to do it reliably and transportably.

I'd just write what you want in Perl, rather than a shell, and use its facilities. Let someone else struggle with the implementation details.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Thank you. We are thinking about Perl threads. In order to code Perl threads however, the compiler must be configured for this and we don't really want to rebuild the compiler for our new component. There are significant programs in Perl that are working fine now and we don't want to disrupt this.

For the cygwin prototype, we have developed a reliable communication system using the shared filesystem. And are programming to explicitly avoid potential issues with resource contention and deadlocks.

It is suprising that Solaris does not have a flock equivalent, however.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: flock in Solaris
 
Similar Threads
check whether files are used by other process
how to target the processes that run on my system/pc
Is there any way to execute a Linux command from Java without fork-ing?
too many files open
Maximum Number of Sockets