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
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
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
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
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
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
How to have a conversation between 2 processes using named pipes? (5 Replies)
Discussion started by: kanchan_agr
5 Replies
7. HP-UX
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
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
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
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