Closed Vishal0802 closed 5 years ago
Thanks for the request. So this functionality is already a part of the jSerialComm library. As soon as a port is opened, the TIOCEXCL flag is set on the port which disables any other processes from opening the port while the current process has it opened. The caveat to this, however, is that a "root" user (or a root-like user with CAP_SYS_ADMIN permissions) will always be able to open the port, no matter what flags are set. This is just a Linux implementation detail, not mine.
Since you are experiencing this problem, I assume you are running multiple processes all from root. Is there the possibility of not using a root user to run your applications? If so, that would be preferable to trying to implement a hacky file-based locking mechanism, if only because it will most likely create additional runtime issues down the line if/when somebody has an application that crashes and the custom locks aren't properly released. Let me know. Thanks!
As a follow-up, I went ahead and implemented an additional method of locking the device using flock() since that should still get cleaned up automatically if a process crashes unexpectedly. Please test the following and see if it works for you:
https://www.dropbox.com/s/ffpxcr0qqphl32k/jSerialComm-2.4.2.jar?dl=0
Hi Will, Thank you so much for your prompt response and the way you guided and then implemented to resolve the same. 1.Yes you are right, we are running through "root" user(As we have this requirement to run project from "root" as well as from any other user account in suse ) in Suse 11 thats why we were getting this issue.
Just a ask and request ,As it looks fine as of now,will you include this feature into your main build. Thanks again the way you worked,It is unexceptionally great.
Regards, Vishal Gupta
No problem. This will be included in version 2.4.2 which will be released publicly today. Thanks!
Linux Suse -11 Issue :Port is not getting locked in the first instance(Java Application) which is allowing another instance(Another java application) to connect with the same port of first instance. Example : ttys0 (Serial port) is connected with first Java application.Now if I start another java application on the same ttys0 port then it is able to connect which is not correct behavior. Ideally it should lock the port when first java application is connected and running. This scenario is working properly in windows.
Please provide the solution to handle this scenario. Thanks in advance.