I need to know if there is any way to force atomicity for a sequence of operations. I have a program that searches for a process and shuts it down if found. The problem is that the time between finding it and killing it leaves room for a user to shutdown the process manually. Then potentially another app could come along and steal the same PID the previous process was using and my application would come along and kill the wrong process.
I need to make sure that from the moment I find the process to when I kill it, no other process has the CPU. Can this be done?