in reply to atomic operations

It looks like that you are searching for a specific process by "name"
(it wouldn't very smart to search for a specific process by PID).

What you can do is:

1- Find the name of the process and its PID
2- Get the owner of this process
3- Get the TTY of this process

When you are going to kill it (you didn't say how much
time later), you need to check if the Name,PID, owner and the
TTY is still the same.. It can reduce drastically this
"race condition" problem.

*Remember that in most operating systems, the PID is not
"random", so you can't just trust on that...

[]'s -DBC