Sponsored Content
Homework and Emergencies Homework & Coursework Questions C Program to search and read all named pipes in current directory Post 302578508 by natwickley on Thursday 1st of December 2011 06:33:45 PM
Old 12-01-2011
C Program to search and read all named pipes in current directory

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

1. The problem statement, all variables and given/known data:


Write a C program to search the current directory for all pipes.

1. It will print the pipe names, one per line.
2. Print the number of pipes found.
3. Search for all pipes whose contents contain your ID and print the entire contents of that/those pipe(s).

2. Relevant commands, code, scripts, algorithms:

Running inside a bash shell, compiling with g++, professor provides a directory of pre-existing pipes and pipe writers to prevent the block that you get from waiting for a pipe read or write to start

3. The attempts at a solution (include all code and scripts):

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main()
{
FILE *read_fp;
char buffer[BUFSIZ + 1];
int chars_read;
memset(buffer, '\0', sizeof(buffer));
read_fp = popen("uname -a", "r");
if (read_fp != NULL) {
chars_read = fread(buffer, sizeof(char), BUFSIZ, read_fp);
if (chars_read > 0) {
printf("Output was:-\n%s\n", buffer);
}
pclose(read_fp);
exit(EXIT_SUCCESS);
}
exit(EXIT_FAILURE);
}

4. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
University of North Texas, Denton, Texas, USA
Course is 3600, "Systems" taught by Professor Goodman
www . cse . unt . edu /~goodman/CS3600/cs3600.html

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).


I don't have a problem reading from the pipe. I can specify a named pipe with the popen command and read from a named pipe. The above code can do that. The problem I have is that I am given the task to read from all the named pipes in the directory using a C program. I can easily write a bash script like "for all files in *" do blah. I know that I can do a system call and I can make a system call for the pwd to figure some things out but I don't know how to isolate pipes from the general files inside the C program. In a bash script I can use "test" to do that but is there a way to suck a list of named pipes into a C program in Unix? Finding named pipe assistance seems to be quite difficult on google so I'm trying out here.

Any ideas how to pull in the list of pipes into the C program?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

named pipes

Hi I am having trouble with a script to export individual schemas to tape from an oracle database. Basicaly I need to export each shema through a pipe with compression and store each shema name in a file with the relevant tape marker. (4 Replies)
Discussion started by: truma1
4 Replies

2. UNIX for Dummies Questions & Answers

create directory named current date

Since this site solved my problems before, I am back for more (solutions) I down load via a script every day a file that has the same name as the file of the day before. I want to move that file to its own directory like: /archive/jul30 How do I capture the systems date in a script an... (2 Replies)
Discussion started by: flowrats
2 Replies

3. 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

4. Shell Programming and Scripting

FIFO named pipes

Hi...Can anyone please guide me on FIFO Pipes in UNIX.I have lerant things like creating fifo pipes,using them for reads and writes etc.I want to know what is the maximum amount of memory that such a pipe may have? Also can anyone guide me on where to get info on this topic from? (1 Reply)
Discussion started by: tej.buch
1 Replies

5. UNIX for Advanced & Expert Users

tee into 2 named pipes

The following code does not work (zsh, Solaris), but works without the first line (files instead of pipes) :confused: mkfifo p1 p2 echo "Hello" | tee p1 > p2 & paste p1 p2 I would high appreciate any help to fix it. (9 Replies)
Discussion started by: zzol
9 Replies

6. Shell Programming and Scripting

named pipes

How to have a conversation between 2 processes using named pipes? (5 Replies)
Discussion started by: kanchan_agr
5 Replies

7. HP-UX

remove named pipes

Hi, Please help me on this. I am creating a named pipe in a kshell script. I am using mkfifo pipe_name command to create the pipe. I want to remove the named pipe after my work is completed. How can i do that. (8 Replies)
Discussion started by: chintapalli001
8 Replies

8. UNIX for Dummies Questions & Answers

Named Pipes

hi, i am working on a script for oracle export, m using a parameter file... i want to compress the dump file that is generated.. in my script following is the code i have written. i am not able to generata .gz file mknod /tmp/exp_tesd1_pipe p gzip -cNf... (4 Replies)
Discussion started by: saharookiedba
4 Replies

9. Shell Programming and Scripting

Create a directory named as the current date

I am preparing a shell script to backup a few config files on a daily basis, with a retention of 30 days. Need some help with syntax/examples: The shell script (running as cron) would require the following: 1. create a sub-directory within a specified (backup) directory, in the format... (3 Replies)
Discussion started by: FeNiCrC_Neil
3 Replies

10. Shell Programming and Scripting

Dialog with an external program using named pipes

Dear community, I communicate with an external program (maxima) using named pipes. If I use a text file to capture the output (maxima > out.txt) i can see the programs answer directly after the input written into the file. But if bypass the output into a named pipe (maxima > pipe) and capture it... (1 Reply)
Discussion started by: Pustekuchen
1 Replies
TOGEOMVIEW(1gv) 														   TOGEOMVIEW(1gv)

NAME
togeomview - send commands or OOGL objects to geomview SYNOPSIS
togeomview [-c] [-g] [pipename [program args ...]] DESCRIPTION
togeomview sends a stream of geomview commands, or OOGL-format geometric data, to a cooperating copy of geomview. If geomview is not run- ning, it is automatically started. ('geomview' must be on the $PATH of the user running 'togeomview' in order for this to work.) Typical usage is: someprogram | togeomview (to send commands) or someprogram-generating-OOGL-data | togeomview -g (to send geometry) i.e. a program pipes geometric data into ``togeomview''; the data is displayed by a copy of geomview run with the -M option and a name matching the one given to togeomview. Togeomview uses a named pipe in the directory /tmp/geomview to communicate with geomview. If unspecified, the pipe's default name is "OOGL". When sending geometry (-g), a geomview object with the same name as the pipe appears in geomview's object browser. By default, when no suitable copy of geomview is running, togeomview invokes "geomview" with arguments specifying the appropriate named pipe. A different command may be specified as in: togeomview OOGL gv -wpos 300x300 -c my_startup_script which communicates through a pipe named OOGL, and (if necessary) invokes the given gv command. The pipe name is required if a command is specified. After togeomview has created it, the named pipe may be written as an ordinary file. For example, one could use togeomview pipename < /dev/null to invoke a listening copy of geomview, and then run a program which simply wrote to /tmp/geomview/pipename. FILES
/tmp/geomview BUGS
The pipe-based communications scheme imposes several restrictions. If no copy of geomview is reading from the pipe, or if geomview gets far enough behind, a program writing data to ``togeomview'' will be forced to block after sending a few kilobytes. Because of the buffering in the pipe, the sender may be substantially ahead of the geomview display. If geomview exits, the sending program receives a write-on-broken-pipe (SIGPIPE) signal, which will kill it unless measures are taken to catch or ignore that signal. Only one copy of geomview can read from a given pipe at a time. If a second copy attempts to read from it, both will probably fail. It's fine to have multiple copies of geomview reading from different pipes. Note that togeomview will invoke geomview if no extant copy is listening to the relevant pipe; it can't connect to an existing copy of geomview started by other means. SEE ALSO
geomview(1), oogl(5) Geometry Center 21 May 1993 TOGEOMVIEW(1gv)
All times are GMT -4. The time now is 07:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy