I'm currently building an application in JAVA where there can be only one execution. So I'm currently using a lock file in which I write the PID of the current execution.
So whenever this application will start, it will open the file (if it exists) and try to detect if the PID written in the file is actually running.
This prevent the problem where my app crash before unlocking the file.
I need this to work both on windows (XP,7 or 8) and linux (all the users are on debian based distros).
Here's some code to give you a better picture of what I want to do :
//get the PID from the file
int pidValue = new FileReader(file).read();
//get the OS type
String os = System.getProperty("os.name").toLowerCase();
//Check PID depending of OS type
if( os.contains("nux") || os.contains("nix") ){
/*
* Check PID on Linux/Unix
*/
} else if ( os.contains("win") ) {
/*
* Check PID on Windows
*/
}
I have tried to find documentation on the subject, but I didn't manage to find anything useful yet.
Thank you very much.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…