in reply to atomic operations

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?
Not as far as I'm aware on say Linux for example. Imagine your process is running and the timer (runs at 100 Hz by default) goes off because your process's time is up. Now the operating system is free to assign the CPU to another process at it's will during one of these ticks (or another hardware interrupt). (Based on the schedule algorithm and they vary.)

Now suppose the operating system were to let processes request to not be interrupted. In that case it's possible one process would keep the CPU forever. Imagine say the process has an infinite loop in it, that bug in a user program could hang the system so nothing else would get the CPU. As far as I know Linux doesn't have any way to let processes request to not be interrupted.

It has been a while since I've looked at the scheduler code (and I hear it has changed) but I recall you could specify priority levels where all processes in a higher priority would be served first. (Note this is different than the "nice" level as I recall.) I'm not sure but you may be able to make your find-and-kill process a higher priority and it won't give up the CPU until it yeilds it by it's own choice.
Update: ie all lower priority processes won't get the CPU unless the higher priority processes (only your one process) have yielded the CPU.

The point is I'm not aware of what you asked for being offered on most common operating systems but I'm not authoritative on the topic.

Replies are listed 'Best First'.
Re^2: atomic operations
by kcella (Beadle) on Jul 11, 2004 at 18:40 UTC
    This is the exact problem I am trying to avoid. Since everyone seems to agree that there is no easy 100% safe way to bypass the CPU scheduler, I will just double check right before I kill the PID (as danielcid recommends) and that should be enough. I am running on a winxp system and there is very little time between finding the PID and killing it. FYI: I use Win32::ToolHelp (to find by name) and Win32::Process (to kill by PID).

    thanks, Kevin