用多进程或单进程运行dhcrelay有什么区别吗?

我想问一下关于运行机制。 我们可以用两个命令运行dhcrelay,然后运行为2进程

dhcrelay -i eth3 172.16.17.3 dhcrelay -i eth1 172.16.17.5 #ps ax | grep dhcre 26464 ? Ss 0:00 /usr/sbin/dhcrelay -i eth3 172.16.17.3 26465 ? Ss 0:00 /usr/sbin/dhcrelay -i eth1 172.16.17.5 

或用一个单一的命令,换句话说,单一的过程

 dhcrelay -i eth3 -i eth1 172.16.17.3 172.16.17.5 #ps ax | grep dhcre 28127 ? Ss 0:00 /usr/sbin/dhcrelay -i eth1 -i eth3 172.16.17.3 172.16.17.5 

我想知道这两种方法之间有什么技术上的区别,除了进程数量?

在查看源代码时 ,有一些东西会跳出来,这似乎受到运行单个命令与多个命令的影响。

首先在dispatch.c这个注释:

 /* * Wait for packets to come in using poll(). When a packet comes in, * call receive_packet to receive the packet and possibly strip hardware * addressing information from it, and then call through the * bootp_packet_handler hook to try to do something with it. */ 

看来, dhcrelay.c使用轮询体系结构 。 在轮询其中一个接口时(例如: -i eth0-i eth1 ),这个查询会使用超时(基于时间)。

这似乎表明,在另一个接口正在被轮询时,有一个阻塞的可能性。

另一个片段,这次在dispatch()函数中,轮询一个指定的接口:

 /* Wait for a packet or a timeout... XXX */ count = poll(fds, nfds, to_msec); 

上面的轮询函数超时或接收到一个包后, dhcrelay进入“下一个”接口:

  /* Get the current time... */ time(&cur_time); i = 0; for (l = protocols; l; l = l->next) { struct interface_info *ip = l->local; if ((fds[i].revents & (POLLIN | POLLHUP))) { fds[i].revents = 0; if (ip && (l->handler != got_one || !ip->dead)) (*(l->handler))(l); if (interfaces_invalidated) break; } i++; } interfaces_invalidated = 0; } while (1); 

请注意,整个dispatch包含一个while(1)循环。

那么,这意味着什么?

我会说,如果你的networking拥有大量主机,而你的DHCP租约相对较短,那么你可能要考虑运行2个dchrelay实例。

但是,如果你的networking相对较小,而且你的DHCP租约超时时间相对较长,那么运行单个实例应该没问题。

一些额外的事情要考虑

  • 运行2个实例允许您为每个维护单独的日志文件。
  • 运行2个实例允许一个中继器在不影响另一个的情况下重新启动。