user6103938
user6103938

Reputation: 21

Busybox udhcpd vfork starts two processes

In my application I require to start Busybox udhcpd (dhcp server), the code is below. While udhcpd does start and run I get two versions in the process list. udhcpd is running correctly, i.e. assigned IP addresses to devices.

pid_t forked_pid = vfork();

if ( forked_pid == 0 )
{
  // Child process, execute udhcpd.
  execl( "/usr/bin/udhcpd",
         "udhcpd",
         "/var/run/udhcpd.conf",   // the location of the udhcpd config file
         NULL );
}
else if ( forked_pid > 0 )
{
  // Parent process, record the childs pid
  m_udhcpd_pid = forked_pid;
  log( Log_Info, "UDHCPD started with PID: %d (PID=%d)", forked_pid, getpid());
}
else
{
  log( Log_Warning, "Failed to start UDHCPD" );
}

Log Output

UDHCPD started with PID: 647 (PID=528)

PS output

528 root       0:03 ./MyApp

647 root       0:00 [udhcpd]

648 root       0:00 udhcpd /var/run/udhcpd.conf

Now if I look at /var/run/udhcpd.pid it has the pid of 648. In another part of our code we start dhcpcd (dhcp client) using the same code as above and it only has one entry in the process list. Can anyone explain what the difference is and if I am doing things incorrectly what I should be doing?

The reason for asking is I require to later stop udhcpd and it seems I will need to stop using both the childs pid (647) and also the pid read from /var/run/udhcpd.pid (648).

Upvotes: 2

Views: 479

Answers (1)

user6103938
user6103938

Reputation: 21

I believe the answer is udhcpd does another fork leaving a zombie process. Reverted to just doing a system call and killing the process using the PID in the PID file.

Upvotes: 0

Related Questions