bash - Un*x shell script: what is the correct way to run a script for at most x milliseconds? -


I am not a scripting expert and I was wondering what an acceptable way to run the script in maximum x milliseconds (And still ends before X Milliseconds if the script is done before the expiry of time).

I have solved this kind of problem in a way that I think is very dangerous and I am surprised that there is a better way of doing this.

Actually I get a shell script sleep_kill.sh which takes the PID as the first argument and gives its second argument as a second time And it does this:

  kill $ 2- $ 9 2 & gt; / Dev / null 1 & gt; / Dev / null  

So if PID matches a script that is before the expiry of time, then nothing is going to kill (I think the OS It will not be time to reuse this PII for another [unrelated] process that 'Cycling' is done before using it again through all the process IDs.)

However, I I can call my script "Hang" or Time Sitting up can be:

  Kmmand_thet_may_hangks PID = $! Sleep_kill.sh $ PID .3 Wait for $ PID & gt; / Dev / null 2 ​​& gt; & Amp; 1  

and I'll wait for command_ath_may_hang.sh for a maximum of 300ms. However if I took only 10 ms to execute command_that_may_hang.sh , then I would not be "trapped" for 300 ms.

It would be great if some shell expert can explain the shortcomings of this approach and what should be done instead.

Look at this script: Note that due to a second-time scheduling delay etc, most systems are highly irresponsible is. Note that the new corollaries contain a timeout command and it has a resolution of 1 second.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -