Thread: Problems with piping (Shell)

  1. #1
    Registered User
    Join Date
    Apr 2014
    Posts
    1

    Question Problems with piping (Shell)

    This is a shell program, in the last part im trying to link multiple processes through piping. This seems to work just fine: ls directs its output to grep and the output of grep is then printed. The problem is that the shell terminates after grep prints or just hangs in an empty line untill ctrl-C is pressed resulting in the shell being terminated. The current output of the program when ls is used:
    gijs@ubuntu:~/Documents/Besturings_systemen/Shell$ ./shell
    /home/joeri/Documents/Besturings_systemen/Shell $ ls
    commands
    commands~
    shell.c
    shell.c~
    try.c~
    Untitled Document~
    ->(terminal hangs here)<-
    The code: [C] Shell - Pastebin.com

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    You defined MAX_LENGTH as 1024; please explain why you think this code is safe?

    Hint: 100 is much less than 1024.

    Tim S.


    Code:
    line = malloc(100 * sizeof(char));
           
            if (!fgets(line, MAX_LENGTH, stream)) {
                break;
            }
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Implementation of Shell -- Problem in multiple piping
    By ani_pwl in forum C Programming
    Replies: 4
    Last Post: 10-22-2011, 10:00 AM
  2. Problem with piping in my simple UNIX shell
    By Integral Birth in forum C Programming
    Replies: 0
    Last Post: 11-28-2010, 07:37 PM
  3. programming unix shell piping problem
    By Kyro in forum Linux Programming
    Replies: 2
    Last Post: 08-28-2003, 07:52 AM
  4. Shell execute... but piping
    By nickname_changed in forum C++ Programming
    Replies: 2
    Last Post: 05-21-2003, 07:39 AM
  5. System.ini Shell Problems
    By (TNT) in forum Windows Programming
    Replies: 2
    Last Post: 08-26-2001, 01:05 PM

Tags for this Thread