Solved

detecting proc-id

Posted on 2004-04-06
2
211 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
2 Comments
 
LVL 17

Expert Comment

by:owensleftfoot
Comment Utility
#!/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 50 total points
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now