ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
It is possible to run multiple instances of a jar executable. Is it possible that only a single instance of the jar runs? Wrappers like JSmooth or Launch4J can be made to run as a single instance. But since there are no such wrappers for linux, I need a way to restrict the jar to a single instance. How to embed the jar file into an executable such it runs a single instance?
Suppose I take any OS (Linux for that matter) and any virtual machine (QEMU, VirtualBox), and start an number of OS instances in the virtual machines - each of the OS instances running only one instance of your 'jar' file.
Suppose there is some limiter for one user - how can it "fight" with another user (I mean user ID - not necessarily another person) - how can the limiter limit another user's activity ?
If you are serious, you need some kind of license server for your application, but even that is easily circumvented by virtual machines - unless your license server phones home, but then probably nobody would like to deal with you in the first place.
How to embed the jar file into an executable such it runs a single instance?
You could have the first instance create a file using "open" with O_CREAT and O_EXCL. You can add a check for the file or just use the error from "open" to cause any other instances to exit when they try to create the file.
You could have the first instance create a file using "open" with O_CREAT and O_EXCL. You can add a check for the file or just use the error from "open" to cause any other instances to exit when they try to create the file.
O_EXCL
If O_CREAT and O_EXCL are set, open() shall fail if the file exists. The check for the existence of the file and the creation of the file if it does not exist shall be atomic with respect to other threads executing open() naming the same filename in the same directory with O_EXCL and O_CREAT set. If O_EXCL and O_CREAT are set, and path names a symbolic link, open() shall fail and set errno to [EEXIST], regardless of the contents of the symbolic link. If O_EXCL is set and O_CREAT is not set, the result is undefined.
.
So, how will O_EXCL prevent from creating a file in a different directory and/or under different user ID ?
The same questions apply to the "heavier" approach with virtual machines.
So, how will O_EXCL prevent from creating a file in a different directory and/or under different user ID?
Can you show me where the OP says he needs to prevent execution across virtual machines?
In his original post he described the mechanism whereby a Windows program can detect if it is the first instance or not. That mechanism does not work across virtual machines.
You are trying to solve a problem that the OP does not have.
Can you show me where the OP says he needs to prevent execution across virtual machines?
In his original post he described the mechanism whereby a Windows program can detect if it is the first instance or not. That mechanism does not work across virtual machines.
You are trying to solve a problem that the OP does not have.
The OP says he/she wants single instance of a jar file to run. I do not see in which environment and for which purpose the OP wants it.
FWIW, even if there is a wrapper around Java bytecode interpreter, another Java bytecode interpreter (installed in a different place, having different classpath, etc.) may run another instance of the same jar file.
The OP says he/she wants single instance of a jar file to run. I do not see in which environment and for which purpose the OP wants it.
If you knew what Launch4J and JSmooth were, you would know he was asking to duplicate the mechanism used by Windows. If you knew what the Windows mechanism was, you would understand what his goal was.
I don't think he's trying to implement anything other than prevent multiple instances of the same application (ignore the Java specifics for now) from running.
Thunderbird is an example of an application that does this. Years ago, you could open multiple instances of Thunderbird. But that turns out to be inconvenient. So they modified it so you can only run one instance.
Quote:
Originally Posted by Sergei Steshenko
FWIW, even if there is a wrapper around Java bytecode interpreter, another Java bytecode interpreter (installed in a different place, having different classpath, etc.) may run another instance of the same jar file.
If both instances are trying to create a file at the same location in the file system (e.g. "/var/tmp/a_file_name"), the second instance will exit. It is a commonly used mechanism.
If you knew what Launch4J and JSmooth were, you would know he was asking to duplicate the mechanism used by Windows. If you knew what the Windows mechanism was, you would understand what his goal was.
I don't think he's trying to implement anything other than prevent multiple instances of the same application (ignore the Java specifics for now) from running.
Thunderbird is an example of an application that does this. Years ago, you could open multiple instances of Thunderbird. But that turns out to be inconvenient. So they modified it so you can only run one instance.
If both instances are trying to create a file at the same location in the file system (e.g. "/var/tmp/a_file_name"), the second instance will exit. It is a commonly used mechanism.
Yes, but the question is "what for/why ?". If the application can exist as only one instance for functional reasons (like Email client) - that's one story, and if the application licenser wants yo limit one instance per seat for license fees reason - that's another story.
If you knew what Launch4J and JSmooth were, you would know he was asking to duplicate the mechanism used by Windows. If you knew what the Windows mechanism was, you would understand what his goal was.
I don't think he's trying to implement anything other than prevent multiple instances of the same application (ignore the Java specifics for now) from running.
Thunderbird is an example of an application that does this. Years ago, you could open multiple instances of Thunderbird. But that turns out to be inconvenient. So they modified it so you can only run one instance.
If both instances are trying to create a file at the same location in the file system (e.g. "/var/tmp/a_file_name"), the second instance will exit. It is a commonly used mechanism.
Exactly. I need to achieve that. Like Thunderbird which allows only one instance to run. What I am designing is an input method like SCIM. So, I'm logging all the key presses, processing them and then outputting the converted text to the window which has focus. Basically, it's an input method (Hope you people know what an input method is). Since i'm logging key presses, I need to run a single instance of the program or else it will create a conflict.
Exactly. I need to achieve that. Like Thunderbird which allows only one instance to run. What I am designing is an input method like SCIM. So, I'm logging all the key presses, processing them and then outputting the converted text to the window which has focus. Basically, it's an input method (Hope you people know what an input method is). Since i'm logging key presses, I need to run a single instance of the program or else it will create a conflict.
So, I'm logging all the key presses, processing them and then outputting the converted text to the window which has focus.
He has an application that grabs all input and modifies it before sending it to whatever application has the focus. This kind of thing is used to help people with disabilities use computers. In this case, he tells us exactly what he is using it for: an input method.
He is trying to help people get around the limitations of their keyboards. He is not trying to prevent them from using his software.
Please read the posts until you understand them. If you don't understand them, ask questions until you do. All this unhelpful noise is just wasting bandwidth.
He has an application that grabs all input and modifies it before sending it to whatever application has the focus. This kind of thing is used to help people with disabilities use computers. In this case, he tells us exactly what he is using it for: an input method.
He is trying to help people get around the limitations of their keyboards. He is not trying to prevent them from using his software.
Please read the posts until you understand them. If you don't understand them, ask questions until you do. All this unhelpful noise is just wasting bandwidth.
???
It was you who suggested to use "open" with O_CREAT and O_EXCL, so why can't the OP use your suggestion, creating/checking fixed name file in fixed directory like /tmp ?
At the time of starting the application - write an entry into a certain file to true (lets call it X). Ensure at the time of closing the application this entry is set to false.
And before starting execution of teh application - check whether the value in this file is true or false. If it is true - exit the application.
This will prevent multiple instances of the application from working on one machine.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.