我有一个“服务器”进程,会产生一些日志。我希望用户(或其他服务)能够查看该日志流(类似于tail -f
),但我不想将这些日志写入文件系统。在Linux上我可以这样做吗?
My first attempt was to use UDP, on the loopback interface. The server sends packets to localhost on port 12345, and clients can bind to that port to receive them. Doesn't work. Because only one client can bind to the same socket. Ah! But you might say use SO_REUSE_ADDR, that lets two clients bind to one port, but only one receives the messages.
Next up, I tried UDP multicast on the loopback interface. That one didn't get so far, as my kernel doesn't support multicast on the loopback interface. According to
ifconfig
:lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:186 errors:0 dropped:0 overruns:0 frame:0 TX packets:186 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:11904 (11.6 KiB) TX bytes:11904 (11.6 KiB)
Note the lack of
MULTICAST
(orBROADCAST
, indeed), above.
请问有什么想法吗?我可以使用命名管道或Unix域套接字来解决这个问题吗?
我希望避免任何可能会影响特权服务器的非特权侦听器的东西。例如,我宁愿放弃日志而不是阻止服务器。
如果有的话,我正在使用Python进行所有操作。
select
,poll
,epoll
)来连接客户端,维护活动客户端列表,并在生成最新日志时立即将其发送给它们。可能更好的方法是使用管道将日志从主服务器传递到辅助 TCP/UDP 服务器,并在那里进行循环。 - Jason Hu