Creating locks based on pids would'nt help. Each process that starts off, gets a new pid.
You mention that multiple scripts are involved. This is the chain of commands that I understood.
script1 -> script2 -> native code
i.e. script1 does something, calls script2, does something and then your app. is called.
This is what you should do.
Script1 checks for 'no ps count' and 'no lock file'. Hence your app. is not running. Create a lockfile and start script2.
Script2 checks for lock file and 'starts your app.' and 'deletes the lockfile'.
Now when you run script1 again, it will fail because will find 'ps count'.
Try it out.
Hope I didnt make any fatal flaws/assumptions.
'no ps count' is your original ps command.
vino