Sponsored Content
Full Discussion: Pipe & fifo....
Top Forums Programming Pipe & fifo.... Post 24785 by M3xican on Wednesday 17th of July 2002 04:45:19 PM
Old 07-17-2002
Question Pipe & fifo....

Could someone Help me with this code please?

Code:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
#include <fcntl.h>

#define SIZE_B 256      /*buffer's size */
#define NUM_ARG 20      /* max number of args for any command  */

int main()
{
	char *arg1[NUM_ARG];
	char *arg2[NUM_ARG];
	int pippa;	
	pid_t pid1,pid2;
	
	arg1[0]="ls";	/*first command*/
	arg1[1]="-l";
	arg1[2]=0;
	
	arg2[0]="grep";	/*second command*/
	arg2[1]="mishell";
	arg2[2]=0;
	
	mkfifo("./mishell_pipa",S_IRWXU);       /*make fifo*/

        pippa=open("./mishell_pipa",O_RDWR|O_CREAT|O_TRUNC|O_SYNC);    /*get fd*/   

	unlink("./mishell_pipa");       /*unlink file*/

	if(!(pid1=vfork()))	/*first process*/
	{
		dup2(pippa,STDOUT_FILENO);
		execvp(arg1[0],arg1);
		_exit(0);
	}
	else
	{
		waitpid(pid1,NULL,0);	/*wait first process*/
			
		if(!(pid2=vfork()))	/*second process*/
		{
			dup2(pippa,STDIN_FILENO);
			execvp(arg2[0],arg2);
			_exit(0);
		}
		else
			waitpid(pid2,NULL,0);	/*wait second process*/
	return 0;
	}
	
}

I have to create a pipe between 2 process such as the output of the first process
is the input of the second.
In practice I have to do the same thing that the bash does using the follow command:

ls -l|grep mishell

The program works well, but after that grep gives me its output it doesn't come back to
the shell, but stays blocked.

I have tried also to use the mode O_NONBLOCK in the open function, but so the first problem leaves
its place to another. The programm works well, but at the end grep gives me this error:

grep: (standard input): Resource temporarily unavailable

I think that the problem is that grep attend a particular kind of input to terminate, and ls doesn't
give it this input. I've tried to write a EOF in the fifo after the execution of ls, but there
aren't changes.

What can I do????
Help me please!
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

PIPE and FIFO buffer size

Hello! How I can increase (or decrease) the predefined pipe buffer size? Thanks! (1 Reply)
Discussion started by: Jus
1 Replies

2. Shell Programming and Scripting

Reading from blocking fifo pipe in shell script

Hi!! I have a problem reading from a fifo pipe in shell script. The idea is simple, I have a C program with two pipe files: An input pipe I use to send commands in shell script to the C program (echo "command" > input.pipe) An output pipe that I read the result of the command also in... (4 Replies)
Discussion started by: victorin
4 Replies

3. UNIX for Dummies Questions & Answers

fifo or named pipe working?

Can someone explain to me the working of fifo() system call using simple C programs so that I can implement them in the UNIX environement? (1 Reply)
Discussion started by: lvkchaitanya
1 Replies

4. Programming

C++ How to use pipe() & fork() with stdin and stdout to another program

Hi, Program A: uses pipe() I am able to read the stdout of PROGAM B (stdout got through system() command) into PROGRAM A using: * child -> dup2(fd, STDOUT_FILENO); -> execl("/path/PROGRAM B", "PROGRAM B", NULL); * parent -> char line; -> read(fd, line, 100); Question:... (2 Replies)
Discussion started by: vvaidyan
2 Replies

5. UNIX for Dummies Questions & Answers

Search for & edit rows & columns in data file and pipe

Dear unix gurus, I have a data file with header information about a subject and also 3 columns of n rows of data on various items he owns. The data file looks something like this: adam peter blah blah blah blah blah blah car 01 30 200 02 31 400 03 57 121 .. .. .. .. .. .. n y... (8 Replies)
Discussion started by: tintin72
8 Replies

6. UNIX for Advanced & Expert Users

Why not SIGPIPE for readers of pipe/FIFO?

Hi This is a exercise question from Unix network programming vol2. Why the SIGPIPE signal is generated only for writers when readers disappear. why not it is generated for readers when writer disappears. I guess, if the writer didn't get any response like the reader gets EOF, it will... (4 Replies)
Discussion started by: kumaran_5555
4 Replies

7. Programming

Pipe & fifo size limit

Hi guys. 1. how much is the size of pipe?(i mean the buffer size) 2. is this size different in various UNIX derivations? 3. what happens if we write to a full pipe? does it block until get some free space(the other side receive data) or returns an error? 3. FIFO s are physical files on the... (2 Replies)
Discussion started by: majid.merkava
2 Replies

8. Shell Programming and Scripting

awk reading from named pipe (fifo)

I'm trying to read a fifo using awk and comming across some problems. I'm writing to the fifo from multiple processes invoked by GNU Parallel: mkfifo my_fifo awk '{ a = a + $2 } END { for (i in a) print i, a }' my_fifo | sort -nk1 > sorted_output grep -v '^@' massive_file | parallel... (3 Replies)
Discussion started by: nathanhaigh
3 Replies

9. Shell Programming and Scripting

Named Pipe & Oracle imp

Hi, I have a little knowledge about mkfifo, first-in-first-out, a special file, a named pipe and it involves inter-process communication, as multiple processes can write data into a single file. Here, I would like to know how this is helpful in executing the below Oracle 'imp' command... (1 Reply)
Discussion started by: Dev_Dev
1 Replies

10. Shell Programming and Scripting

UNIX fifo concurrent read from a named pipe

I have created a fifo named pipe in solaris, which writes the content of a file, line by line, into pipe as below: $ mkfifo namepipe $ cat books.txt "how to write unix code" "how to write oracle code" $ cat books.txt >> namepipe & I have a readpipe.sh script which reads the named... (2 Replies)
Discussion started by: naveen mani
2 Replies
FSSYNC-DEBUG_STATS(8)					       AFS Command Reference					     FSSYNC-DEBUG_STATS(8)

NAME
fssync-debug_stats - Displays various statistics SYNOPSIS
fssync-debug stats -cmd <subcommand> [-arg1 <arg1>] [-arg2 <arg2>] [-reason <sync protocol reason code>] [-programtype <program type code>] [-help] fssync-debug s -c <subcommand> [-arg1 <arg1>] [-arg2 <arg2>] [-r <sync protocol reason code>] [-p <program type code>] [-h] DESCRIPTION
The fssync-debug stats command displays statistics according to the value of the option -cmd. OPTIONS
-cmd <subcommand> Specifies statistics subcommand. Available subcommands are: o pkg -- general volume package statistics o vicep -- vice partition statistics o hash -- volume hash chain statistics o hdr -- volume header cache statistics o vlru -- vlru generation statistics o help -- display list of available subcommands -arg1 <arg1> Specifies first optional argument, in the context of the chosen subcommand. For vicep statistics, it specifies partition name; for hash statistics, it specifies hash bucket number; for vlru statistics it specifies vlru generation number. -arg2 <arg2> Specifies second optional argument, in the context of the chose subcommand. Currently, none of the subcommands use it. -reason <sync protocol reason code> Specifies numeric sync protocol reason code. Available codes are listed in OpenAFS source file src/vol/fssync_inline.h. For SYNC_REASON_NONE, use -reason 0. -programtype <program type code> Specifies program type code. Permitted values are fileServer, volumeUtility, salvager, salvageServer, volumeServer and volumeSalvager. PRIVILEGE REQUIRED
The issuer must have write access to the file server. Usually, this means that the issuer must be the local superuser "root" on the file server machine. SEE ALSO
fssync-debug_header(8), fssync-debug_query(8) COPYRIGHT
Copyright 2010 Davor Ocelic <docelic@spinlocksolutions.com> This documentation is covered by the IBM Public License Version 1.0. This man page was written by Davor Ocelic for OpenAFS, based on documentation from Steven Jenkins, Tom Keiser and Simon Wilkinson. OpenAFS 2012-03-26 FSSYNC-DEBUG_STATS(8)
All times are GMT -4. The time now is 11:25 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy