Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

detecting proc-id

Posted on 2004-04-06
2
Medium Priority
?
264 Views
Last Modified: 2010-05-18
Hi!

I am running a process in linux or unix which I need to run only one process at a time. How can i write a script wherein the user can only execute one process at a time? If the process is already running then it will not run again until the process currently executing is completed.

Any help or comment would be very much appreciated.

Thanks.
0
Comment
Question by:marou
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 17

Expert Comment

by:owensleftfoot
ID: 10770515
#!/usr/bin/perl
$psaux =`ps aux`;
$result = $psaux !~ /myprocessname/;
if ($result) {
system("mycommand");
}
is sort of what you are looking for.
0
 
LVL 40

Accepted Solution

by:
jlevie earned 200 total points
ID: 10779547
You can do in the shell with:

if [ `ps -ef | grep procname | grep -v grep | wc -l` -gt 0 ]; then
  echo "Process procname is already running, sorry"
  exit 1
else
  echo "Starting  procname"
  /path-to/procname
fi
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question