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
pipe(2) 							System Calls Manual							   pipe(2)

NAME
pipe() - create an interprocess channel SYNOPSIS
DESCRIPTION
creates an I/O mechanism called a pipe and returns two file descriptors, fildes[0] and fildes[1]. fildes[0] is opened for reading and fildes[1] is opened for writing. A read-only file descriptor fildes[0] accesses the data written to fildes[1] on a first-in-first-out (FIFO) basis. For details of the I/O behavior of pipes see read(2) and write(2). By default, HP-UX pipes are not STREAMS-based. It is possible to generate the kernel so that all pipes created on a system are STREAMS- based. This can only be done for HP-UX releases 10.0 and later. STREAMS-based FIFOs (created by or are not supported on HP-UX. To generate a kernel that supports STREAMS-based pipes: o STREAMS/UX must be installed. o The module and the driver must be included in the file. (When STREAMS/UX is installed, and are automatically added to the system file.) o The tunable parameter (see streampipes(5)) must be set to 1 in the file. (This is not automatically done when STREAMS/UX is installed.) o The kernel must be generated and the system rebooted. Once this is done, all pipes created by will be STREAMS-based. For more information, see EXAMPLES
The following example uses to implement the command string RETURN VALUE
returns one of the following values: Successful completion. Failure. is set to indicate the error. ERRORS
sets to one of the following error values if the corresponding condition is true. or more file descriptors are currently open. The system file table is full. The file system lacks sufficient space to create the pipe. Could not allocate resources for both Stream heads (STREAMS-based pipes only). SEE ALSO
sh(1), read(2), write(2), popen(3S), privileges(5), streampipes(5), streamio(7). STANDARDS CONFORMANCE
pipe(2)
All times are GMT -4. The time now is 09:35 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy