Terminating Lua Subprocess

I have incorporated Lua into an Objective-C application using LuaObjCBridge. I need to know how to stop a Lua process if it takes too long (infinite loop?).

Will it run the help in a separate thread?

+2


a source to share


3 answers


The usual way to do this is to use lua_sethook to schedule a callback for every count

VM instruction; when the lua_Hook callback function occurs after an excessive amount of time, when your hook function may raise an error , forcing your guarded call to be managed .



+6


a source


Doug's answer already provides the default needed to restrict the execution of normal lua code. If you need to restrict this for security reasons, you should be aware that there are known ways to use calls to the lua library, such as string matching functions), to create practical infinite loops. The command counting hook won't catch them for you, since the lua command does not increase when a function call is made to c. To solve this caliber, you need OS-level constraints (separate process, interrupt from SIGALRM?)



+4


a source


For OS level constraints such as the mention of kaizer.se, one good approach for running standalone Lua systems on * nix systems is to use ulimit -t 1

to limit the Lua process to one second of cpu time. This is the CGI script approach that the live demo on Lua.org uses.

For an application like the one you described, the best option is to use environment resources.

0


a source







All Articles