how to stop execution of a program if it is already running?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
how to stop execution of a program if it is already running?
Hi all
how to stop execution of a program if it is already running?
I wrote a bash script and create a icon for that script.
In that script first I check running process with
ps -ef
if that process in list I will stop further execution of that script with message "Application is already running".
Script starts with single click on that icon if I use double click on that icon or clicked many times on that icons continuously It display a message "Application is already running" for all clicked.
If I clicked many times on that icons with some interval in that case it works fine.
The typical way this is done is to create lock file, such as programname.pid file in /var/run when your program starts up, and remove it when it ends. The first thing your program does is to check the existence of that file, and refuse to run if it exists.
The typical way this is done is to create lock file, such as programname.pid file in /var/run when your program starts up, and remove it when it ends. The first thing your program does is to check the existence of that file, and refuse to run if it exists.
How do I create lock file. Please explain it.
What I understood is:
if [ -e /var/run/programname.pid ]; then
"already running"
else
create /var/run/programname.pid
start process
rm -f /var/run/programname.pid
fi
it is not solve my problem. When I double click on icon it will start start same process twice. If i gave some interval between two clicks thee it will works fine.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.