LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   prevent opening a program if running (https://www.linuxquestions.org/questions/linux-software-2/prevent-opening-a-program-if-running-643303/)

PB0711 05-19-2008 01:52 PM

prevent opening a program if running
 
Dear all,

Is there a way to prevent others running a program if the program is already running or if the program is running and doing calculations.
I have a box and my users keep logging in and running multiple instances of the program and the computer either dies or it just takes ages for everyones stuff to finish (and then they complain).

Is there a website to look at.
I was thinking I could use perl and top but how do I get top to not produce text constantly. And then how do I stop the user from logging in with Perl?

Thanks,

Paul

chrism01 05-19-2008 06:42 PM

There are a few ways to achieve that:

1. use a lock file and have the prog check if lock file exists. If it does exit, prog is running, so new copy terminates immediately.
2. have prog use
ps -ef|grep <progname>
if prog name found, prog is running, etc
3. check the kernel files (/proc) and do as 2.

I prefer 2, 1 is not reliable if prog creashes, lock file is not removed, 3 is fiddly, but see Proc::ProcessTable::Process (search.cpan.org)


All times are GMT -5. The time now is 12:59 AM.