Linux popen() alternative
#1
Apparently Linux has a problem spawning other processes from a multithreaded process: http://www.linuxprogrammingblog.com/thre...using-them
I've run into this issue while trying to use Lua's io.popen() from the Gallery plugin ( https://github.com/mc-server/Gallery/blo...st.lua#L72 ), it works perfectly on my Windows box, but when trying to run this on a RasPi server, the server freaks out - the server seems to be running fine, but the web request never finishes, the browser is stuck at "Reading from ...", and when I attach GDB, there is no sign of any WebAdmin threads at all. There's also no network activity of any kind, even the MC client port seems closed, although the server still looks as if it is running, it responds to console commands.

So now I need the help of a Linux guru. Is there any alternative to popen that I could use? I don't really need the IO redirection, just spawning the process in the background would be nice, but if there was an IO-redirection-capable solution, that would allow us to override Lua's io.popen() seamlessly.
Reply
Thanks given by:
#2
Wouldn't os.execute work? In windows you can use os.execute("start <process>") to start a new process without blocking the server.
Reply
Thanks given by:
#3
os.execute() seems to work well on the RasPi, I'll try back on Windows. From its documentation I was under the impression that it waited for the process to terminate, which is something I don't want.
Reply
Thanks given by:
#4
Yes, os.execute waits for the child process to terminate. This is pretty useless in the MCS world.
Reply
Thanks given by:
#5
Wait.. it blocked the server on Windows, but not on the RasPi? Then what if you add "start" to the to-be-executed string? "start MCSchematicToPng <arguments>"
Reply
Thanks given by:
#6
Its more complicated than just a Linux solution, this is an issue that faces all POSIX platforms, due to the nature of the fork/exec model. So whilst there are some easy solutions on linux (clone comes to mind), we want a POSIX solution or else we face breaking other POSIX platforms (OS X and *BSD being most significant).
Reply
Thanks given by:
#7
If you don't need the redirection there's posix_spawn on POSIX. It provides the atomicity at the cost of being a more fiddly function. But this will involve custom bindings as there's no way to access it from lua. Its a similar concept to window's CreateProcess.
Reply
Thanks given by:
#8
STR, it blocked the server on both. I just didn't notice at first, because the child process took only a few seconds. Still, can't afford even that - it would mean a 5-second lag in the game.

worktycho, I was hoping for something that we could wrap in an API. If the alternative allows for IO redirection it would be rather nice to translate that into callbacks, if it supports child termination notification, that would be another nice callback to have. If it doesn't allow either of these, then the API would be as simple as a single function call.
Reply
Thanks given by:
#9
According to this: http://askubuntu.com/questions/287350/st...e-terminal

you can put "&" behind the command string on linux to make it execute without blocking the server.
Reply
Thanks given by:
#10
It is somewhat hackish, but it could work. I'll try tomorrow.
Reply
Thanks given by:




Users browsing this thread: 1 Guest(s)