Interprocess communication in Lua scripts

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Interprocess communication in Lua scripts

FrantiÅek Fuka
Hello there,

my problem is probably not with Lua but with lack of Linux knowledge.

Could you please advise me how to implement simple inter-process
communication between several Lua scripts running on Linux using only
the basic Lua facilities (i.e. not having to compile/include any new
Lua modules)?

Let's say I have one Lua process which is constantly running and
acting as a single-threaded server of sorts, and many small Lua
scripts which are invoked as CGI and ask the "server" script for the
data. The server waits for the requests and services them when they
arrive.

I currently implemented the communication using named pipes (e.g.
os.execute("mkfifo ......."), writing to the pipe, waiting for the
reply, removing the pipe...) but this seems unnecesarily cumbersome.
Surely there is some inter-process communication mechanism available
from standard Linux commandline, for Bash scripts for example...???

I didn't try luasocket yet but this also seems like unnecesarily
complex solution for my simple problem...

--
Frantisek Fuka (yes, that IS my real name)
(and it's pronounced "Fran-tjee-shek Foo-kah")
My E-Mail: [hidden email]
My Homepage: http://www.fuxoft.cz
My blog: http://fuxoft.blogspot.com
My Jabber/GoogleTalk ID: [hidden email]
My ICQ: 2745855

Reply | Threaded
Open this post in threaded view
|

Re: Interprocess communication in Lua scripts

Javier Guerra Giraldez
On Sunday 20 August 2006 1:35 pm, Frantisek Fuka wrote:
> I currently implemented the communication using named pipes (e.g.
> os.execute("mkfifo ......."), writing to the pipe, waiting for the
> reply, removing the pipe...) but this seems unnecesarily cumbersome.
> Surely there is some inter-process communication mechanism available
> from standard Linux commandline, for Bash scripts for example...???

in fact, this is the usual way.  most daemons create either pipes or sockets 
somewhere so that other processes (clients) can easily find them.

if you don't like creating and deleting them, you can do it once (at 
installation time) and just reuse the same pipe/socket every time. (i think 
mySQL does so)

-- 
Javier

Attachment: pgpryAR7FE3a7.pgp
Description: PGP signature

Reply | Threaded
Open this post in threaded view
|

Re: Interprocess communication in Lua scripts

David Given
Javier Guerra wrote:
[...]
> in fact, this is the usual way.  most daemons create either pipes or sockets 
> somewhere so that other processes (clients) can easily find them.

If you really need to, there's also the black art of constructing IPC
mechanisms out of file primitives --- it's quite scary, and not at all fast,
but is portable and works everywhere. It tends to be used by shell scripts.

-- 
+- David Given --McQ-+ "Gaping from its single obling socket was
|  [hidden email]    | scintillating, many fauceted scarlet emerald..."
| ([hidden email]) | --- Jim Theis, _The Eye of Argon_ (spelling
+- www.cowlark.com --+ original)


Attachment: signature.asc
Description: OpenPGP digital signature

Reply | Threaded
Open this post in threaded view
|

Re: Interprocess communication in Lua scripts

Sam Roberts-2
In reply to this post by FrantiÅek Fuka
On Sun, Aug 20, 2006 at 08:35:58PM +0200, Frantisek Fuka wrote:
> I didn't try luasocket yet but this also seems like unnecesarily
> complex solution for my simple problem...

sockets should not be complex, and they are the standard unix IPC
mechanism for this sort of thing.

Should be no harder than os.execute("mkfifo"), and advantage of sockets
is they clean up after themselves... Unix domain sockets would be what
you want.

Sam


Reply | Threaded
Open this post in threaded view
|

Re: Interprocess communication in Lua scripts

Javier Guerra Giraldez
Quoting Sam Roberts <[hidden email]>:

> Should be no harder than os.execute("mkfifo"), and advantage of sockets
> is they clean up after themselves... Unix domain sockets would be what
> you want.

other advantages of sockets over pipes (named or not):

- bidirectional communications (no need for two pipes)
- choice of stream or message based (TCP-like or UDP-like)
- multiple clients on one server socket (using the same listen()/accept() calls
like network sockets)



------
Javier