473,396 Members | 1,809 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with simpe unixshell attempt


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
}
Nov 14 '05 #1
2 1016
Seamoon wrote:
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
Nov 14 '05 #2
> 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.
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Michael | last post by:
Hi, thank you for taking your previous time to read the following problem that I face. I'm trying to create multiple child process and TESTCODE 1 work fine, however if I try to connect to MYSQL...
16
by: cody | last post by:
I have to write an algorithm with must ensure that objects are put in buckets (which are always 4 in size). The objects have two properties: A and B. It is not allowed that in a bucket are objects...
6
by: lgn | last post by:
I have test the following program, why the result is not 0 2 4 but 0 2 3? Can someone tell me why the same macro produce different result? Thanks! #include <stdio.h> #define max(a,b) ((a)>(b) ?...
15
by: Ken Allen | last post by:
I have been developing a suite of assemblies over the past couple of weeks, and this afternoon somethign started misbehaving. If I do not run the IDE and compiler the code from the command line,...
8
by: Elliot Temple | last post by:
Problem: Randomly generate 10 integers from 0-100 inclusive, and sum them. Do that twice. What is the probability the two sums are 390 apart? I have code to do part of it (below), and I know how...
2
by: Dennis | last post by:
I'm getting the following problem occasionally...the application will work perfectly well for a period of time and then this pops up. I have tried turning off the default proxy in the...
14
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3 forms. I want allow users to move forward and backward with the forms and retain the data users have entered. I thought...
49
by: Bert | last post by:
Problem is documented at http://ace.delos.com/usacoprob2?a=deAhyErCKsK&S=gift1 Why doesn't this work? /* ID: albert.4 LANG: C TASK: gift1 */
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.