print all nonempty pipe


 
Thread Tools Search this Thread
Top Forums Programming print all nonempty pipe
# 1  
Old 11-17-2011
print all nonempty pipe

I am trying to write a shell script for Linux to print the names of all non empty pipes in the current directory?

any help
# 2  
Old 11-17-2011
ls and find - two main ways to get file information - rely on stat() which is a system call that gets information like the size of a file, file permissions, etc.

The stat call is guaranteed to return a size ONLY if the file in question is a symbolic link or if the file is a regular file. It does not work on pipes.

This means that for most Linux implementations you cannot identify non-empty pipes.

What Linux are you running?
# 3  
Old 11-18-2011
Stat will work on some versions of Unix. Try it out. You could learn something.
Also, you should read the "special homework rules" for this site.
# 4  
Old 11-18-2011
stat only works on Solaris pipes, AFAIK. The OP is on Linux.

If you are going to use C and not a shell script: set the pipe file descriptor non-blocking and then use select() or maybe poll() to see if the file descriptor is available to read or write. Then you do not worry about the "size" of the pipe. Which inofmration is mnot very useful anyway.

Here is some sample code to set the fd non-blocking.
Code:
//error handler 
void errchk(const int val)
{
   if (val == -1)
   {
      perror("Error on pipe");
      exit(1);
   }
}
// set fd to non blocking
void set_no_block(int fd)
{
   int fileflags=fcntl(fd, F_GETFD);

   errchk(fileflags);
   fileflags|=O_NONBLOCK;
   errchk(fcntl(fd, F_SETFD, fileflags));
}

Example use of select (this is a more generic approach for any file descriptor open for read):

The GNU C Library
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Print Date when Broken Pipe happens

Hi all, as i have multiple broken pipes on ssh sessions, i need to find out after how much time it happens, ssh root@testServer root@testServer's password: ssh:notty Last login: Thu Apr 6 06:41:16 2017 from 10.10.10.2 # but when broke pipe happen i don't have any idea after how much... (3 Replies)
Discussion started by: charli1
3 Replies

2. Shell Programming and Scripting

Use less pipe for grep or awk sed to print the line not include xx yy zz

cat file |grep -v "xx" | grep -v "yy" |grep -v "zz" (3 Replies)
Discussion started by: yanglei_fage
3 Replies

3. Shell Programming and Scripting

The pipe not use "tee" to print on the screen for specific function

I have code fragment like { aa bb cc } > $LOG aa bb cc, all call function "ff", I want "ff" to print on the screen,but others do not print on the scree, is there a method? I can't use "tee", becasue tee I meet the write "error" ff() { echo "hello" } (2 Replies)
Discussion started by: yanglei_fage
2 Replies

4. Shell Programming and Scripting

awk print pipe

Hey fellas, I wrote an script which its output is like this: a 1 T a 1 T a 2 A b 5 G b 5 G b 5 G I wanna print $1 $2 and the total number of $2 value as the third column and after that $3. Sth like this: a 1 2 T a 2 1 A b 5 3 G I know how to do it with a given input... (4 Replies)
Discussion started by: @man
4 Replies

5. Shell Programming and Scripting

Print pipe separated list as line by line in Korn Shell

Korn Shell in AIX 6.1 I want to print the below shown pipe (|) separated list line by line. line=es349889|nhb882309|ts00293|snh03524|bg578835|bg37900|rnh00297|py882201|sg175883 for i in line do echo "Hello $line " done I wanted to execute the above for loop. But i can't even set the... (3 Replies)
Discussion started by: polavan
3 Replies

6. UNIX for Dummies Questions & Answers

grep pipe filename print issue

uname -a SunOS mypc 5.10 Generic_141414-07 sun4v sparc SUNW,SPARC-Enterprise-T2000 uname -a SunOS mypc 5.10 Generic_144488-07 sun4v sparc SUNW,SPARC-Enterprise-T5220 find . -name "*.cer" -exec keytool -v -list -printcert -file {} \; | grep -i "Aug 03" Valid from: Mon Jan 29 00:00:00 GMT... (16 Replies)
Discussion started by: shifahim
16 Replies

7. Shell Programming and Scripting

use awk to replace empty fields with the latest nonempty field

Hi suppose I have a csv file like this count,1977,1978,1979 usa, , , blue japan, red, yellow,green india, , yellow,blue china, blue, yellow, green I want the output to be(replace everything, including empty data, with the most recent data): ... (1 Reply)
Discussion started by: grossgermany
1 Replies

8. Shell Programming and Scripting

count number of nonempty columns in row

Hi, Suppose i have a inputfile in csv format. How to use awk to count 'the number of nonempty columns in each row' minus one, and add the value as a new column in the end For cosmetic reason, it's even better to include a descriptive label for the last column in the first row. for... (2 Replies)
Discussion started by: grossgermany
2 Replies

9. UNIX for Advanced & Expert Users

How to delete nonempty directory?

How to delete nonempty directory? Thanks (2 Replies)
Discussion started by: xli3
2 Replies

10. UNIX for Dummies Questions & Answers

remove a nonempty directory

How can I remove a non empty directory. ' rmdir directory_name ' complains that the directory is not empty. The same problem happens with ' rmdir directory_name/* ' Thanks (2 Replies)
Discussion started by: babayeve
2 Replies
Login or Register to Ask a Question