Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7911185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:09:14+00:00 2026-06-03T13:09:14+00:00

I have two processes which I am to synchronize. Process A is running as

  • 0

I have two processes which I am to synchronize.

Process A is running as root and creates a Reentrant-Lock on a specific file.
Process B is running under a “normal” user and should wait for the lock being releases by process A.

I tried many ways but cannot get it working because of wrong file permissions.
Here is the code:
(removed the in-VM-synchronisation-stuff):

Lock:

FileChannel channel = new RandomAccessFile(pFile, "rw").getChannel();
lock = channel.tryLock();

hasLock:

RandomAccessFile file = new RandomAccessFile(pFile, "rw");
FileChannel channel = file.getChannel();
FileLock lock = channel.tryLock();
if (lock == null) {
 return true;
}
lock.release();

The problem I have is that the lock gets created as:

-rw-r--r--. 1 root root 0 May  7 21:42 lockfile.lock

if I try to check the lock (by process B running as normal user) I get a

java.io.FileNotFoundException: _lockfile_ (Permission denied)
    at java.io.RandomAccessFile.open(Native Method)
    at java.io.RandomAccessFile.<init>(RandomAccessFile.java:212)

I tried to umask the directory to all g=rwx,o=rwx but this seems to be ignored. I tried to create the file first, setWritable(true, false) but this seems to be resetted. I did not get any method to work. I tried to use mode “r” instead of “rw” in hasLock but this leads to a ChannelNotWritableException.

So the main question is: how can I influence the permissions of the created lockfile?

Does anyone has some suggestions?

Regards Michael

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T13:09:15+00:00Added an answer on June 3, 2026 at 1:09 pm

    Finally I got a solution:

    The way of first creating the file was the correct one. The mistake I made was that I set the permissions before file creation (expecting that the permissions are stored in the file object and used on creation). I have to first create the file, then set the permissions to all and then lock it:

    file.createNewFile();
    file.setWritable(true, false);
    FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
    channel.tryLock()
    

    the lockfile is now created with worlwide-writable (this may be a security issue but actually there is no problem visible as the file does not contain any content.

    Thanks to everyone helping me to find a solution!

    Regards Michael

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two processes which exange messages each other. Process A is a normal
I have two processes - a user process and a root-level LaunchDaemon. I'd like
I have two running processes in Windows, and each process has a pipe to
i have the following Problem: i have two Processes process A which starts process
I have two processes which access to the same physical memory(GPIO data addr). So
We have a vxWorks design which requires one task to process messages from two
I have two C++ processes (A and B), executing under Windows, where one launches
I have two unrelated processes that use .NET assemblies as plugins. However, either process
I have two processes which are communicating over a pair of sockets created with
i have to write program, which will create two child processes These processes would

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.