Join Stack Overflow to learn, share knowledge, and build your career. I want to ensure that my logic is correct here. I want to run a process for timeout seconds, if it runs for longer it should be immediately killed. The completed flag should reliably indicate whether the process completed as intended, e. Also, I am not positive if the check to process. WaitForExit returns false and Kill succeeds, then will process.
HasExited always be true? That would be my assumption but I wanted to confirm. Also, what if anything can be done if Kill fails, besides just logging?
According to MSDN ,. If you started the process using this component, the system updates the value of HasExited automatically, even if the associated process exits independently. However, if your process crashes and terminates before your timeout, then your code will set it as completed anyway.
Maybe you should check the exit code, but it can have different meanings for each process:. For crashes, there are some approaches here and here , but generally you can't detect crashes for all processes. In C, you could set an OS alarm using the alarm function. You can use this. It is a C wrapper over the JobObjects functionallity.
The idea behind is low level outline that is embedded inside the library I mentioned:. Also using job objects you can restrict memory usage. On the page I mentioned you can find examples also. After I wrote the above statements I have found this Kill child process when parent process is killed. They use the JobObjects for another task, but the usage of JobObjects should be the same as for your case.
To ensure that asynchronous event handling has been completed, call the WaitForExit overload that takes no parameter before checking HasExited. We use the following in a. Mike de Klerk 5, 4 22 I'm using this way too. Could to explain more about this lcryder? I assume you implement this code in the application that is allowed to run for a specified amount of time.
So controlling it internally. But Sean Thoman seems to be looking for a way to control it externally. Externally isn't a problem. Demi 1, 1 15 I don't know any C though, so this was the best response I could think of. FelipeAlcacibar were you the one who downvoted me, and if so does your comment show why? And i am the one who upvoted you. FelipeAlcacibar sorry about that.
The idea behind is low level outline that is embedded inside the library I mentioned: Create a job object. Configure the job object to have a time limit of x seconds.
Create a process and before resuming it assing it to the job object. The process will be killed by the operating system when the time passes. YOu usually get notified by a non zero return code, or a callback. Claudiu 1, 9 Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password.