Piping and redirection implementation


 
Thread Tools Search this Thread
Top Forums Programming Piping and redirection implementation
# 1  
Old 12-19-2006
Piping and redirection implementation

To implement the facility of piping and redirection I used the two commands dup, dup2, and strtok for tokenizing the command.
But when I run the command
ls|more
it is not running fine as I have developed it using the dup2 command.
the more command needs the whole buffer at once.

Please help which system call should I use to implement and maintaining the output in a buffer of one command so that it can be used as a input to other command.



Thanks
# 2  
Old 12-19-2006
You've been told to build pipes without using pipes? Is this homework?
# 3  
Old 12-19-2006
It is probably homework, but I'm sure you are allowed to use pipes (as in pipe(2)). No one is going to ask for an implementation the pipe system call.
# 4  
Old 12-20-2006
I am using the pipe command but I am unable to run it successfully
The command like
ls|more

Please help how to implement that piping.
# 5  
Old 12-20-2006
pipe() is a C system call. Use it to program "ls|more"
# 6  
Old 12-20-2006
Quote:
Originally Posted by mobile01
I am using the pipe command but I am unable to run it successfully
Ah. Here are the steps.
  • Call pipe() to create two fd's for the pipe.
  • Call fork() to create a new process.
  • Parent code:
    • Close the reading-end of the pipe, the parent doesn't need it.
  • Child code:
    • Close the writing-end of the pipe, the child doesn't need it.
    • Duplicate the reading-end over standard input.
    • Close the original reading-end of the pipe, leaving only the duplicate.
    • Call exec() to replace this process with whatever program you want to pipe to. It will keep the file descriptors you've given it, in this case, the pipe.
You should now be able to write to the writing end of the pipe in the original process, and have the data be fed into the standard input of the other process.
# 7  
Old 12-20-2006
Thanks, But I got stuck when the command length is more than 3 pipes. I made that program and is running fine on 3 pipes but more than that my program is not able to handle.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

C: CSV implementation

I have this code from a programming book: #include <stdio.h> #include <string.h> char buf; /* input line buffer */ char* field; /* fields */ char* unquote( char* ); /* csvgetline: read and parse line, return field count */ /* sample input:... (3 Replies)
Discussion started by: totoro125
3 Replies

2. Shell Programming and Scripting

Back up implementation

Is there any command to take create back up of a file as soon as when it is created?If not is it possible to create something like that? (3 Replies)
Discussion started by: Sindhu R
3 Replies

3. UNIX for Advanced & Expert Users

Ipsec implementation

How can i implement Ipsec between two machines in linux_ ubuntu? any link?? suggestion?? (0 Replies)
Discussion started by: elinaz
0 Replies

4. UNIX for Dummies Questions & Answers

Lseek implementation

Hi everybody, i've been googling for ages now and gotten kinda desperate... The question, however, might be rather trivial for the experts: What is it exactly, i.e. physically, the POSIX function (for a file) "lseek" does? Does it trigger some kind of synchronization on disk? Is it just for the... (4 Replies)
Discussion started by: Humudituu
4 Replies

5. Linux

CAPWAP implementation

Hi I'm trying to implement CAPWAP protocol for my application.i'm able to configure my server side but i'm getting error at client(WTP) side as IOCTL error.while running the command #./WTP /mnt/cf/capwap/ : wlan2 Starting WTP... # WTP Loads... (0 Replies)
Discussion started by: ran789
0 Replies

6. Programming

Implementation of dup2

Hi all,I'm reading <Advanced programming in the UNIX environment>,that book asked the reader to implement a function which has same functions with dup2 without calling fcntl.Could anyone give me a tip?Any help will be appreciated.:) (8 Replies)
Discussion started by: homeboy
8 Replies

7. Programming

Malloc implementation in C

Hey Guys I am trying to implement the malloc function for my OS class and I am having a little trouble with it. I would be really grateful if I could get some hints on this problem. So I am using a doubly-linked list as my data structure and I have to allocate memory for it (duh...). The... (1 Reply)
Discussion started by: Gambit_b
1 Replies

8. UNIX for Advanced & Expert Users

Implementation of ls - i command

It is possible for me to obtain the Inode of the path name using ls -i <pathname> command Can anyone tell me how its implemented... (3 Replies)
Discussion started by: ganapathy.psgit
3 Replies

9. Programming

Java with Unix (Redirection + Piping)

Hi, To explain this question I will have to go into a bit of detail. I hope you don't mind. currently I have a log handler (an already compiled c++ version) and what it does is makes a log file and writes all the unix output (echo, etc) of a script to that log file. To me the log_handler is... (3 Replies)
Discussion started by: fluke_perf
3 Replies

10. Shell Programming and Scripting

Redirection or piping error message

I have written a script that appears to work correctly in testing, but is coming up with a starnge error message, script_name: test: 0403-004 Specify a parameter with this command. Redirection or piping of stdin or stdout is allowed only with -b. (156). The script is run by different... (2 Replies)
Discussion started by: mariner
2 Replies
Login or Register to Ask a Question