Script lock functionality

Hi All,

My requirement is i have a script A.sh .When a person A runs the script A.sh it should get locked and person B should not run the script.
i followed the below code

f_script_lock()
{
process=$1
user=`ps -ef | grep -i "$process"  | grep -i 'ksh' | awk '{print $1;}'` 
	 if [ ! -z $user ]; then
        echo "Recovery  is handled by $user. Hence cannot proceed in Recovery" 
	 exit
	 else
	 continue
	 fi
}

The above is working fine in normal conditions.
But when person A runs the query and press Ctrl+C intermitently the code stops running.
When person B or even person A tries to execute the A.sh again after sometime it says it has been accessed by the user and not able to execute.
Please help me on this.

You might want to work with a lock file that is written to the filesystem and check if it exists or not. Maybe write the PID into it and if the file is existent, check if a process is still running with that PID etc.
Additionally you can use trap to intercept signals like that of ctrl+c.