Skip to Main Content
Hands-On System Programming with Linux
book

Hands-On System Programming with Linux

by Kaiwan N. Billimoria, Tigran Aivazian
October 2018
Beginner content levelBeginner
794 pages
19h 23m
English
Packt Publishing
Content preview from Hands-On System Programming with Linux

Putting it together – our simpsh project

So, now that we have all the bits and pieces in place—namely, the fork-exec semantic and the wait API—we can see how our simple shell should be designed.

In the C program, get into a loop, display the required prompt, accept user input (let's use the fgets(3) to do this—why? Please read the upcoming tip) into a cmd variable, and then fork. In the child code (use fork rule #2 to distinguish between the parent and child), use one of the many exec family APIs (a simple execlp(3) sounds promising here) to execute the user supplied command. In parallel (recall fork rule #3), have the parent process invoke the wait API; the parent now sleeps until the child dies. Now loop around again and repeat the whole ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux System Programming Techniques

Linux System Programming Techniques

Jack-Benny Persson
Linux Device Drivers, Second Edition

Linux Device Drivers, Second Edition

Jonathan Corbet, Alessandro Rubini

Publisher Resources

ISBN: 9781788998475Supplemental Content