I am going to write an application that will be able to manage Internet connection. Is it possible to run and stop dhclient
from C code without using system()
function?
Asked
Active
Viewed 129 times
0

John Kugelman
- 349,597
- 67
- 533
- 578

qwarky
- 19
- 4
-
1The `system()` function can be used to execute any program/command, therefore also `dhclient`, if the permissions of your executable/process allow that. For a quick test, that's fine, but it might make more sense to use existing system facilities (like systemd) to control/start/stop services. There's a related question: https://stackoverflow.com/questions/52053475/start-stop-enable-disable-a-systemd-service-from-c – rel Mar 07 '21 at 10:01
-
1execve() executes the program pointed to by filename. – Gábor Mar 07 '21 at 22:36
-
Why don't want you to use `system()`? – Mathieu Mar 08 '21 at 08:39
-
@Mathieu I am in the same boat, when I tried to run dhclient on an interface from C code using system(), there is a chance we can run into issue if the spawned dhclient is not cleared when the interface goes away, in my case it reboots the system if the interfaces goes away and the C app is still running. – Aravind Mar 16 '21 at 18:03