Problem with simpe unixshell attempt

S

Seamoon

I'm trying to do a simple unixshell and have some problems with the
pipeprocedure.
The procedure will generate a correct result when for example executing
rwho|grep nnn|wc,
but if bground is set to 0, I want the pipe to execute in the foreground
such that the prompter will be displayed after the
result is printed, but the pipe still executes in the background so that the
result is displayed after the prompter. I suppose I'm doing something wrong
when waiting for the first child to terminate (executing the last command in
the pipe)?
cmdList is a linked list of arrays each holding the command (pgms[0]) and
accompanying switches pgms[1..n] for each process in the pipe..
Perhaps it can be immediately seen if I'm doing something conceptually
wrong?

Best regards,

Simon

void execPipe(Pgm *cmdList, int bground, Command info) {
pid_t childPid;
char **pgms;
int status;

childPid = fork();
if (childPid == 0) {
pgms = cmdList->pgmlist;
if (info.rstdout) {
close(1);
creat(info.rstdout, O_RDWR|O_CREAT);
}
while (1) {
int p[2];
pipe(p);
if (!fork()) {
close(0);
dup(p[0]);
close(p[0]);
close(p[1]);
execvp(pgms[0], pgms);
perror("Unknown command");
_exit(1);
}
cmdList = cmdList->next;
pgms = cmdList->pgmlist;
close(1);
dup(p[1]);
close(p[1]);
close(p[0]);
if (!cmdList->next) {
if (info.rstdin) {
close(0);
open(info.rstdin, O_RDONLY);
}
execvp(pgms[0], pgms);
perror("Unknown command");
_exit(1);
}
}
}
else
if (!bground)
waitpid(childPid, &status, 0); //Doesn't seem to block til the
last process in the pipe is terminated
}
 
A

Allin Cottrell

Seamoon said:
I'm trying to do a simple unixshell and have some problems with the
pipeprocedure.

Wrong newsgroup. Try comp.unix.programmer Here we talk about standard C

Allin Cottrell
 
S

Seamoon

Wrong newsgroup. Try comp.unix.programmer Here we talk about standard C

Oki, my bad. I was to quick to ask anyway. Case solved now.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,366
Latest member
IanCulpepp

Latest Threads

Top