
Linux System Programming Techniques
By :

What we just covered regarding using fork()
, waitpid()
, and execl()
to start a new program in a forked process is the key to understanding Linux and processes at a deeper level. This understanding is key to becoming an excellent system developer. However, there is a shortcut. Instead of manually dealing with forking, waiting, and executing, we can use system()
. The system()
function does all these steps for us.
For this recipe, you only need what's listed in the Technical requirements section of this chapter.
In this recipe, we'll rewrite the previous program—my-fork
—using the system()
function instead. You'll notice how much shorter this program is compared to the previous one. Let's get started:
sysdemo.c
. Notice how much smaller (and easier) this program is. The system()
function does all the complex stuff...