简体   繁体   中英

check if a java process exists in linux

I need something to check if another instance of the same java program is already running on Linux when the program start. If yes, the program need to exit to avoid two services running at the same time.

Does anybody know the best practise?

Thanks

Do it like the most linux programs are doing.

Put a file with your pid into /var/run/[Program].pid or/var/run/[Program]/pid

Getting list of processes in Linux can be done in many ways. For something specific to Java, check this thread: List of Java processes (on Stackoverflow)

You will possibly get your answer there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM