A couple of days ago I was needing to solve an issue with our EAI framework. The implementation of such framework could be basically described as instances of Java programs running under Solaris, but there’s a particular instance that should be running just once. So I wrote this tiny shell script to avoid launching that program twice:
#!/bin/ksh
#
theProcess=someProcess
if [ $(pgrep -u $USER -f $theProcess | wc -l) -gt 0 ] then
echo “There is an instance of “$theProcess” already running.”
else runTheProcess
fi
someProcess could be any regex that matches the process description,
runTheProcess is whatever command that executes the process.
Okay, that’s all, I hope you’ve found it informative and thanks for reading!








![Ubuntu Feisty Fawn + Oracle Database 10g XE [WebApp] Ubuntu Feisty Fawn + Oracle Database 10g XE [WebApp]](http://farm2.static.flickr.com/1345/1086311454_f6fc5002f5_t.jpg)
perhaps you should check it like so:
…
if [ $(pgrep -u $USER -f $theProcess | wc -l) -gt 0 ]
…
just in case
Thanks for your comment chubbs! I’m modifying the original code in the post to include your suggestion!