GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Nov-2007, 21:41
student28 student28 is offline
New Member
 
Join Date: Nov 2007
Posts: 3
student28 is on a distinguished road

Need help supporting linux pipes in a C shell program


I'm new to C shell programming. I started off with the limited shell program listed. The program compiles and runs great, but does not support pipes ("|"), redirection of stdin, stdout and stderr just like Linux does.

Does anyone have any ideas on how this can be implemented in the C shell. The code was too long to paste here. I have attached a txt file myshell.txt. Also see link below:

linuxgazette.net
Attached Files
File Type: txt myshell.txt (4.4 KB, 21 views)
  #2  
Old 27-Nov-2007, 22:46
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,496
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Need help supporting linux pipes in a C shell program


Quote:
Originally Posted by student28
... does not support pipes ("|"), redirection of stdin, stdout and stderr just like Linux does.
If this is an assignment from an operating systems course, you should know that LInux is not a shell. (If you are looking at writing a shell, even if it is not for a course assignment, you should know that an operating system is not a shell.)

Typical Linux distributions for PCs ship with the bash shell, and source is available for your reference. (I actually browsed it a long time ago, but didn't find it very illuminating. Maybe I just wasn't motivated enough. I mean, all those goto statements! My head hurts just thinking of it.)

Various other "real world" shells make their source available for your reference. One such is tcsh.

Here's a quote from a comment in sem.sh.c, one of the 54 C source files in the current tcsh package:

" * sh.sem.c: I/O redirections and job forking. A touchy issue!"

In other words, it's not just a matter of a "fixup" of the verrry rudimentary (toy) shell from your reference.

Here's a reference for tcsh: http://www.kitebird.com/csh-tcsh-book/

You can get source from here:ftp://ftp.astron.com/pub/tcsh/

A package named "busybox" is used on many embedded Linux systems. It comes with a shell called "ash". Kind of a clone of a cut-down bash. (Has i/O redirection and many other features of bash, but not command history, for example.)

I haven't actually looked at the source for ash, but I have been through other parts of busybox, and I found some of the code almost understandable. You should be able to find some references on the web (including the source).

Regards,

Dave
  #3  
Old 27-Nov-2007, 23:03
student28 student28 is offline
New Member
 
Join Date: Nov 2007
Posts: 3
student28 is on a distinguished road

Re: Need help supporting linux pipes in a C shell program


I never wrote anywhere in my post that Linux or any operating system is a shell. If this is what my post implies, my apologies. What I meant to say was that I wanted my shell program to support Linux commands, which in fact it does. The only thing I cannot do from the shell was the of use pipes ("|").

Thanks for the information in the links though.
  #4  
Old 27-Nov-2007, 23:27
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,496
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: Need help supporting linux pipes in a C shell program


Quote:
Originally Posted by student28
I never wrote anywhere in my post that Linux or any operating system is a shell.

I'm sorry if I sounded snippy, but that's what I thought you said. ("the program does not support...like Linux does".)

Linux is a kernel. It does not have commands.

Of course, I knew what you meant, and everyone talks about "Linux command lines" and stuff like that.

Sometimes I have a hard time expressing my passion for precision in narrative (as well as in programming) without sounding grouchy. Thank you for your indulgence.

Regards,

Dave
  #5  
Old 28-Nov-2007, 09:28
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 932
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: Need help supporting linux pipes in a C shell program


So, what you are doing is running a C program out of a bash environment, right?
And is the problem with fork and execve?
Have you searched this list on "fork" etc.?
That turns up several threads which may be helpful. One in particular is:
http://www.gidforums.com/t-3369.html?highlight=fork
I think someone was doing linux pipes not too long ago...
I'm not a forking professional, but played around a little and remember getting into pthreads which I thought worked nicely as well.
Do you have man pages on your distro? It's all there...

If you were to reduce your code to just what is necessary to illustrate your problem it would probably get more views and so a better response from the forum.
Last edited by Howard_L : 28-Nov-2007 at 10:53.
 
 

Recent GIDBlogNot selected for officer school by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help supporting linux pipes ("|") student28 Computer Software Forum - Linux 0 27-Nov-2007 21:26
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 10:13
How to make Linux shell calls in a C++ program salmaz8347 C++ Forum 3 14-Oct-2005 06:59
[TUTORIAL] Calling an external program in C (Linux) dsmith C Programming Language 4 22-Apr-2005 13:30
Call a C program through Linux shell script nuwandee C Programming Language 3 29-Mar-2004 21:54

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 18:51.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.