Is it possible to set time limit for process? I realize that this can be done using multithreading. For instance I could use one thread that executes the process and an other thread that kills it after the some amount of time, but isn’t there a more simple solution?
Share
No, because such a solution would not know exactly how to stop the process after the time limit has elapsed. Killing the process outright is potentially dangerous stuff, so in the general case the process needs to cooperate for a graceful shutdown to be achieved.
It’s really not that difficult to set up a timer and have your main loop check for a condition that signifies the timer has elapsed.