1

Is there a mechanism in Perl to share a socket between two separate processes-- without forking or threading in Linux?

I would assume no, but this answer leaves me to believe it is possible: https://stackoverflow.com/a/1139425/1170839

I would like to create a listening socket on one process, and allow another process to accept/read/write on it.

Community
  • 1
  • 1
GoldenNewby
  • 4,382
  • 8
  • 33
  • 44

2 Answers2

6

On many UNIXy systems, as the link you posted indicates, file descriptors may be passed over local domain sockets. For example, a privileged process can open/prepare an fd and then send it to an unprivileged process for use.

Socket::MsgHdr exposes this functionality for perl, and includes examples of file descriptor passing.

pilcrow
  • 56,591
  • 13
  • 94
  • 135
-1

The way to go is to use POE. POE makes multithreading in perl ridiculously easy and is designed for just this. POE is a CPAN framework for event driven multithreaded applications. Hands down, the easiest and best way to do this in Perl is POE. There's no reason to reinvent this when it's all been done before and is so well tested.

See:

http://poe.perl.org/?Evolution_of_a_POE_Server and http://poe.perl.org/?POE_Cookbook/TCP_Servers

hsanders
  • 1,913
  • 12
  • 22
  • 5
    Misleading — POE is not "multithreading." Also, not germane — the OP is specifically looking for socket sharing between *separate processes*. – pilcrow May 01 '12 at 20:01