Alternative of system() in c Linux to execute a terminal command on linux

BKT picture BKT · Jun 5, 2015 · Viewed 6.9k times · Source

I want to execute a terminal command of Linux in a C program. Currently I am using system() function but I want to use any other as the system() function is banned as per MISRA.

For example, how can I replace

 system("hwclock --systohc --utc");

Answer

Sourav Ghosh picture Sourav Ghosh · Jun 5, 2015

You can make use of fork() and then look up for exec() family of functions.

Alternatively, you may want to have a look at popen() also.