I use the system () call to run tail -f.
One thing that I saw is that calling the tail takes 2 processes (I see in ps): 1) sh -c tail filename 2) the name of the tail file
As the man page says: system () executes the command specified in the command by invoking the / bin / sh -c command. I think process 1) is inevitable, right?
I'm just wondering if I can reduce the number of processes from 2 to 1.
Thanks in advance.
always executes the sh -c command. If you want only one process, run the system command ("exec tail -f").
fork()/exec() . system() , , .
fork()/exec()
system()
/* Untested code, but you get the idea */ switch ((pid = fork())) { case -1: perror("fork"); break; case 0: execl("/usr/bin/tail", "tail", "-f", filename); perror("execl"); exit(1); default: wait(pid); ... }