Take a ganders at Linux Application Development by Michael K Johnson and Erik W. Troan
In my Edition (2nd) you develop a simple shell (ladsh) as part of some examples (in 10.7) in pipes and process handling. A great educational resource.
Proved very useful for me.
A snippet:
struct childProgram {
pid_t pid; /* 0 if exited */
char ** argv; /* program name and arguments */
};
struct job {
int jobId; /* job number */
int numProgs; /* total number of programs in job */
int runningProgs; /* number of programs running */
char * text; /* name of job */
char * cmdBuf; /* buffer various argv's point into */
pid_t pgrp; /* process group ID for the job */
struct childProgram * progs; /* array of programs in job */
struct job * next; /* to track background commands */
};
void freeJob(struct job * cmd) {
int i;
for (i = 0; i < cmd->numProgs; i++) {
free(cmd->progs[i].argv);
}
free(cmd->progs);
if (cmd->text) free(cmd->text);
free(cmd->cmdBuf);
}
You can find the full source here under ladsh1.c
, ladsh2.c
and so on.