Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

detecting proc-id

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
marou
Asked:
marou
1 Solution
 
owensleftfootCommented:
#!/usr/bin/perl
$psaux =`ps aux`;
$result = $psaux !~ /myprocessname/;
if ($result) {
system("mycommand");
}
is sort of what you are looking for.
0
 
jlevieCommented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now