LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-02-2003, 03:23 AM   #1
jiahe
LQ Newbie
 
Registered: Feb 2003
Posts: 1

Rep: Reputation: 0
Question Pipeline implementation in C


I'm a student in uni, currently taking a course in OS.
My current crisis is in implementing a pipeline using C.

The implementation below allows TWO commands to be piped:
---------------------------------------------------------------------
main(int ac, char *av[]){

int p[2];
pipe(p);

if(fork( ) ){

dup2(p[1],1)
close(p[0]); close(p[1]);
execlp(av[1], av[1], 0);

}
else {

dup2(p[0],0);
close(p[0]); close(p[1]);
execlp(av[2],av[2],0);
}
}
---------------------------------------------------------
when the command is executed:
a.out who wc

the effect is the same as executing:
who | wc

The problem is to modify the above program such that the command:

a.out command1 command2 command3 ... commandN

has the same effect as:

command1 | command2 | command3 | ... | command N

using only the five system calls: dup2( ), pipe( ), execlp( ), fork( ), close( ).
Can any one help, pls?
 
Old 02-02-2003, 06:23 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
no, we are not here to do your homework for you. if your uni is worth a light then they will have provided you with ample resources to deal with this assignment.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
noob Pipeline help. promero Programming 8 09-11-2005 04:42 PM
C(sockets):how to implement persistent and pipeline supermyself Programming 0 06-09-2005 01:42 PM
Having a tough time with K-shell pipeline pjz Programming 4 03-24-2005 04:05 PM
pipeline buffering jk3us Linux - Software 2 12-17-2004 08:52 PM
pipeline using rm verstapp Linux - General 3 03-09-2004 12:33 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration