Sponsored Content
Top Forums Programming C, unix, pipes, fork, recursion Post 302667179 by tarasque on Thursday 5th of July 2012 05:32:32 PM
Old 07-05-2012
C, unix, pipes, fork, recursion

Hi, I will try to keep my post as compressed as my title was.
I am writing on pseudo code on a recursive function that I want to read from the one-above function-run and then give the result to the function-run down below until a stop is triggered. Example:
Code:
$ ls -la | grep x | sort

In my function what I want ls to run and send the result to the next function call.
What I've got so far:
Code:
main:
create a char **program_names and set int times_to_run to amount of names.
call rec(program_names, times_to_run)

rec(char** program_names, int times_to_run):
if times_to_run is 0 return, else do
int fd[2]
pipe(fd)
replace stdout with fd[1]
fork
parent:
    execl(*(program_names+times_to_run))
child:
    replace stdin with fd[0]
    //waitpid(getppid()) ?
    call rec(program_names, times_to_run-1)

Does this seem right? I'm having a hard time with recursion. Smilie
Cheers.

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by vbe; 07-06-2012 at 05:44 AM..
 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

PIPEs and Named PIPEs (FIFO) Buffer size

Hello! How I can increase or decrease predefined pipe buffer size? System FreeBSD 4.9 and RedHat Linux 9.0 Thanks! (1 Reply)
Discussion started by: Jus
1 Replies

2. UNIX for Advanced & Expert Users

Interprocess communication using pipes and fork

I'm very worried. I have an assignment that is due in 3 weeks, and also tute exercises which I can't seem to understand and work out. Okay, the question: The parent process will convert the command arguments into integer values using atoi() and store them into an integer array which you will... (2 Replies)
Discussion started by: scmay
2 Replies

3. UNIX for Dummies Questions & Answers

Cannot fork , too many process - SCO Unix 5.05

I need a help... I have a HP Netserver LH 6000 U with Hardware Raid . Sco 5.0.5 installed with Oracle database. Total number of users, normally logged in are around 60 nos. The system is very slow ( takes 6 hours for processing one Lakh bills) during the Billing process. Also it is... (1 Reply)
Discussion started by: saleeshpl
1 Replies

4. UNIX for Dummies Questions & Answers

How to write a script by fork() in unix

Hello to UNIX Champs, Can any body help me out to write the script using fork() thru shell scripting.....i am a layman to fork(), so please give me the link or any scripts which will help me out to know the details about fork. (1 Reply)
Discussion started by: manas_ranjan
1 Replies

5. Programming

Recursion

I want to halt a tail recursive function after certain validation. I want to come out of entire recursion without unwinding phase. How can i achieve that . The coding is done in C language. (5 Replies)
Discussion started by: joshighanshyam
5 Replies

6. Shell Programming and Scripting

How Unix tee to send pipeline output to 2 pipes ?

Hi, I would like to process, filter the same ASCII asynchronous live data stream in more than one pipe pipeline. So the one pipeline should filter out some records using grep key word and more than one pipes pipelines each should grep for another key words, each set seperately for each... (5 Replies)
Discussion started by: jack2
5 Replies

7. UNIX for Dummies Questions & Answers

Quick help with UNIX commands (pipes and filters)

Hey all, I need a command line that creates a new file named whatever, say stuff.txt in the current working directory which contains the number of directories in the current working directory, followed by the number of empty files in the current working directory, followed by the name of the... (2 Replies)
Discussion started by: corpsegrinder
2 Replies

8. SCO

-sh: fork failed - too many processes in sco unix 5.0.5

Dear experts, I have done a re-installation of sco unix openserver 5.0.5 and managed to create users. The problem am facing is that of one user logging in more than 5 times. How can i overcome this problem. the system give the error below. -sh: fork failed - too many processes in sco unix... (5 Replies)
Discussion started by: njoroge
5 Replies

9. Programming

C++ socket, fork & pipes

Hello, I'm stuck and this is a matter which I need to resolve quite fast (but I couldn't post in the "Emergency" section); the problem is this : I have created a chat program in which the client sends the sentence to the server and then the server should send it to all the clients connected,... (2 Replies)
Discussion started by: timmyyyyy
2 Replies

10. Shell Programming and Scripting

Troubles with pipes, fork, and dup2

I want to execute metasploit by two pipes to communicate with it, but I have troubles with that communication. When I run my program, I get this error: "stty: standard input: Inappropriate ioctl for device" and I don't receive the metasploit promt. just select an exploit. This is my code:... (2 Replies)
Discussion started by: dano88
2 Replies
ZGREP(1)                                                      General Commands Manual                                                     ZGREP(1)

NAME
zgrep - search possibly compressed files for a regular expression SYNOPSIS
zgrep [ grep_options ] [ -e ] pattern filename... DESCRIPTION
Zgrep invokes grep on compressed or gzipped files. These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*). All other options specified are passed directly to grep. If no file is specified, then the standard input is decompressed if necessary and fed to grep. Otherwise the given files are uncompressed if necessary and fed to grep. If the GREP environment variable is set, zgrep uses it as the grep program to be invoked. EXIT CODE
2 - An option that is not supported was specified. AUTHOR
Charles Levert (charles@comm.polymtl.ca) SEE ALSO
grep(1), gzexe(1), gzip(1), zdiff(1), zforce(1), zmore(1), znew(1) ZGREP(1)
All times are GMT -4. The time now is 09:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy