fork&pipe "interpretting" shell - problem


 
Thread Tools Search this Thread
Top Forums Programming fork&pipe "interpretting" shell - problem
# 1  
Old 04-13-2009
fork&pipe "interpretting" shell - problem

hello everybode.Got some sort of "problems" with this stuff;
well this is a program
Code:
int main()
{
    int Pipe[2];
    int origStdin, origStdout;
    int childPID;
    origStdin = dup(0);
    origStdout = dup(1);
    pipe(Pipe);
    if( (childPID = fork()) < 0 )
    {
        perror( "Fork Error" );
        exit(-1);
    }
    if( !childPID )
    {
        dup2( Pipe[0], 0 );
        dup2( origStdout, 1 );
        close( origStdout );
        close( origStdin );
        close( Pipe[0] );
        close( Pipe[1] );
        execlp( "/bin/sort", "sort", NULL );
        perror("Execl error");
        exit(-1);
    }
    dup2( Pipe[1], 1 );
    close( Pipe[0] );
    close( Pipe[1] );
    close( origStdout );
    close( origStdin );
    execlp( "/bin/cat", "cat","a.txt","b.txt", NULL );
    perror( "EXEC Error");
    return 0;
}

problem is that :after the work hav done it[program] (unfortunatly top utility do not show nor cat nor sort) stuck(freezes or smth) )just got it whats that!
it tty or who? do not show its bash-blablabla-$ ? why? and how to make to show this string?
Smilie

Last edited by jim mcnamara; 04-13-2009 at 01:26 PM.. Reason: added code tags
# 2  
Old 04-13-2009
wrong forum section.
anyway.....
# 3  
Old 04-14-2009
This program appears to work correctly for me, and I cannot figure out what your question is.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (14 Replies)
Discussion started by: thisissouvik
14 Replies

2. AIX

How to use 'expect' to pass UID & Password to a "for loop" in shell script?

Friends, Need someone's help in helping me with the below requirement for a script: > For a list of servers(over 100+), I need to login into each of them(cannot configure password-less ssh) & grab few configuration details < I know, this is possible through expect programming in a simple... (2 Replies)
Discussion started by: thisissouvik
2 Replies

3. Web Development

How would I mod_rewrite "/~a1Pha" and "/=a1Pha" to "/paste/a1Pha.htm"? (internally & externally)

Basically I want to shorten URLs on my html pasting site (pasteht.ml), by using "/~a1Pha" instead of "/paste/a1Pha". The ID is 5 numbers and letters, both cases. For example: /~idnum serves /paste/idnum.htm /=idnum serves /paste/idnum.htm /paste/idnum redirects to /~idnum (to update any old... (0 Replies)
Discussion started by: phillips1012
0 Replies

4. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

5. Red Hat

files having Script which works behind "who" & "w" commands

Dear All, plz print the path of files which have the script of "who" & "w" commands. thnx in advance. (6 Replies)
Discussion started by: saqlain.bashir
6 Replies

6. UNIX for Dummies Questions & Answers

Problem using unix command with "&"

Hello, I've tried running several commands but am not getting the results I expect. Just to give you some background: 1) I'm running windows vista 2) I'm using Putty and have enabled X11 forwarding 3) I have also installed xming 4) I am using a free unix shell acount from devio.us 5) The... (5 Replies)
Discussion started by: Tazor44
5 Replies

7. Shell Programming and Scripting

How to include RETURN KEY with Background process "&" in Shell Script

Hello All, I am a newbie in Shell script programming, and maybe you can help me with my query. I need to write a shell script (mntServer.ksh) that will start a background process and also to be able to run another script. The mntServer.ksh script contains: #!/bin/ksh... (1 Reply)
Discussion started by: racbern
1 Replies

8. Shell Programming and Scripting

shell script & sqlplus "plzz help"

hi friends, i m tryin to load data from one set of table to other i have sql procedure al ready for it..! i m going to load the procedure only if data in one of my table for example table "landing " have 10 records each attribute of this table is file_name status date ... (2 Replies)
Discussion started by: kulbir
2 Replies

9. UNIX for Dummies Questions & Answers

Encoding Problem while using "|" (PIPE) as delimiter from Mainframe to Unix

We are facing a problem with PIPE (|) as a delimiter in one of our FTP flat files. We are constructing a Flat file in IBM-AIX and this contains various strings delimted by PIPE Symbol and then FTPing this to a Mainframe System The Mainframe program simply recieves this and FTPs the same... (1 Reply)
Discussion started by: seshendra
1 Replies

10. Shell Programming and Scripting

korn shell "loops & arrays"

Hi, I am trying to write a script which will loop until a certain action has been performed. I have two files i would like to compares. For example: file1 has a list of user ids (about 900) from the company's e-mail server. file2 has a list of user ids (about 50 or so) from... (7 Replies)
Discussion started by: muzica
7 Replies
Login or Register to Ask a Question