srikanthradix
asked on
How to set Semaphore
We have a ksh shell script. Sometimes, this ksh script is executed multiple times due to some error in the calling program which we do not have control over. Until that is fixed, we are planning to use semaphore type control so that it won't be executed twice.
I got a semaphore example from "http://www.csm.astate.edu/~rossa/semab.html" semabinit.c program.
How to have semaphore type control over ksh shell script?
I got a semaphore example from "http://www.csm.astate.edu/~rossa/semab.html" semabinit.c program.
How to have semaphore type control over ksh shell script?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Explanation:
Check if process with PID in file exists by sending it SIGNULL
|| - if return <> 0
Launch script in background
store new PID into file
Check if process with PID in file exists by sending it SIGNULL
|| - if return <> 0
Launch script in background
store new PID into file
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for solution. it is working perfectly fine.
echo $! > /var/run/myscript.pid