You are not logged in.

#1 2012-03-22 07:28:53

bsdson.tw
Member
From: Taiwan
Registered: 2005-05-06
Posts: 161

[solved] pipe does not work?!

Hi,

somehow I found following commands give me nothing:

ps | grep bin

ps and grep do work and give me correct results by following:

ps > ps.out
grep bin ps.out

I wondering how this can happen?!
And how can I figure out what's going wrong?!

Thanks.

BR,
bsdson

edit: this problem is not related to "pipe" but the option I used in the "grep" command.

Last edited by bsdson.tw (2012-03-30 11:04:36)

Offline

#2 2012-03-22 07:30:30

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [solved] pipe does not work?!

┌─[Archer ~]
└─╼ ps
  PID TTY          TIME CMD
13500 pts/2    00:00:00 bash
13816 pts/2    00:00:00 ps

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2012-03-22 07:36:16

Gcool
Member
Registered: 2011-08-16
Posts: 1,456

Re: [solved] pipe does not work?!

Extract from ps manpage:

       By default, ps selects all processes with the same effective user ID
       (euid=EUID) as the current user and associated with the same terminal
       as the invoker. It displays the process ID (pid=PID), the terminal
       associated with the process (tname=TTY), the cumulated CPU time in
       [dd-]hh:mm:ss format (time=TIME), and the executable name (ucmd=CMD).
       Output is unsorted by default.

What output containing "bin" are you seeing exactlty by just running "ps"?


Burninate!

Offline

#4 2012-03-23 02:53:13

bsdson.tw
Member
From: Taiwan
Registered: 2005-05-06
Posts: 161

Re: [solved] pipe does not work?!

I have aliased my "ps" as:

alias ps='/bin/ps -U henry -o pid,bsdstart,state,rss,args -H'

and the output is like:

[henry@henry_u59 ~]$ ps
  PID  START S   RSS COMMAND
  821  15:19 S  9340 gnome-session
  848  15:19 S 17408   /usr/lib/gnome-settings-daemon/gnome-settings-daemon
  883  15:19 S 99180   /usr/bin/gnome-shell
1018  15:20 S 21628     gnome-terminal
1025  15:20 S   720       gnome-pty-helper
1026  15:20 S  3808       bash
26206  10:49 R   948         /bin/ps -U henry -o pid,bsdstart,state,rss,args -H
1101  15:20 S 308832     firefox
1177  15:20 S 111988       /usr/lib/firefox/plugin-container /usr/lib/mozilla/p
1144  15:20 S 85172     skype
2272  16:17 S  1676     /bin/bash /usr/bin/eclipse
2273  16:17 S   964       /usr/share/eclipse/eclipse
2288  16:17 S 697284         /opt/java/bin/java -Xms40m -Xmx384m -XX:MaxPermSiz
5555  18:09 S 50420     empathy
  896  15:19 S  7680   ibus-daemon --xim
  902  15:19 S  3588     /usr/lib/ibus/ibus-gconf
  904  15:19 S 32284     python2 /usr/share/ibus/ui/gtk/main.py
  935  15:19 S 46200     /usr/lib/ibus/ibus-engine-chewing --ibus
  900  15:19 S 10112   nm-applet
  905  15:19 S 13932   /usr/lib/gnome-disk-utility/gdu-notification-daemon
  907  15:19 S 13320   gnome-screensaver
2352  16:17 S  1268 adb fork-server server
1511  15:43 S  2748 /usr/lib/gvfs/gvfsd-metadata
1502  15:43 S  3560 /usr/lib/gvfs/gvfsd-trash --spawner :1.6 /org/gtk/gvfs/exec
1116  15:20 S  2972 /usr/lib/at-spi2-core/at-spi-bus-launcher
1066  15:20 S 14176 /usr/lib/telepathy/telepathy-gabble
  998  15:20 S  5768 /usr/lib/telepathy/telepathy-logger
  996  15:20 S  5136 /usr/lib/libsocialweb/libsocialweb-core
  951  15:19 S 14252 /usr/lib/gnome-online-accounts/goa-daemon
  947  15:19 S  6060 /usr/lib/telepathy/mission-control-5
  943  15:19 S  4188 /usr/lib/gvfs/gvfs-gdu-volume-monitor
  941  15:19 S  6264 /usr/lib/gnome-shell/gnome-shell-calendar-server
  913  15:19 S  7472 /usr/lib/ibus/ibus-x11 --kill-daemon
  892  15:19 S  2920 /usr/lib/dconf/dconf-service
  877  15:19 S  4888 /usr/lib/gnome-settings-daemon/gsd-printer
  872  15:19 S  7208 /usr/bin/pulseaudio --start --log-target=syslog
  874  15:19 S  2636   /usr/lib/pulse/gconf-helper
  865  15:19 S  2540 /usr/lib/gvfs//gvfs-fuse-daemon /home/henry/.gvfs
  858  15:19 S  2396 /usr/lib/gvfs/gvfsd
  846  15:19 S  3036 /usr/lib/GConf/gconfd-2
  839  15:19 S  5600 /usr/bin/dbus-daemon --fork --print-pid 5 --print-address 7
  838  15:19 S   600 /usr/bin/dbus-launch --sh-syntax --exit-with-session
  804  15:19 S 13100 /usr/bin/gnome-keyring-daemon --daemonize --login

this command

ps | grep <some text> 

always works, until recently...

another command with "pipe" does not work neither:

alias | grep ps

BR,
Henry

Offline

#5 2012-03-23 04:26:23

MisterAnderson
Member
Registered: 2011-09-04
Posts: 285

Re: [solved] pipe does not work?!

Using ps is a bit different to ps -U Henry -o pid,bsdstart,state,rss,args -H, but nevertheless it should work. I just ran first the full command (with my username) and piped it to grep and it gave the correct output, then I aliased it to ps, and ran that, and it worked, so I don't know what's going on. Also, alias | grep ps worked as well.


D:

Offline

#6 2012-03-23 11:25:45

Gcool
Member
Registered: 2011-08-16
Posts: 1,456

Re: [solved] pipe does not work?!

Would it be possible to post your entire .bashrc?


Burninate!

Offline

#7 2012-03-24 01:57:05

MisterAnderson
Member
Registered: 2011-09-04
Posts: 285

Re: [solved] pipe does not work?!

Sure.

[greg@spacebar ~]$ cat .bashrc 
#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

alias ls='ls -F'
PS1='[\u@\h \W]\$ '

alias pacman='sudo pacman'

Try making a backup of your .bashrc file, then stripping back to basics, logging out and logging back in and see if it still happens.

EDIT: Haha woops, thought GCool was OP asking me. Anyway, my suggestion still stands.

Last edited by MisterAnderson (2012-03-24 01:57:58)


D:

Offline

#8 2012-03-26 03:12:05

bsdson.tw
Member
From: Taiwan
Registered: 2005-05-06
Posts: 161

Re: [solved] pipe does not work?!

Here is mine:

[henry@henry_u59 ~]$ cat .bashrc
#
# ~/.bashrc
#

# If not running interactively, don't do anything
[[ $- != *i* ]] && return

shopt -s checkwinsize

complete -cf sudo
complete -c man

export EDITOR=vim

export HISTCONTROL=erasedups

export PAGER=less

export GREP_OPTIONS="-I --color=auto --devices=skip --directories=recurse -s"

PS1='[\u@\h \W]\$ '

# ------------------------------------------------------------

# ls
alias ls="ls --color=auto -q"
alias la="ls --color=auto -Aq"
alias ll="ls --color=auto -lhGq"

# file
alias diff="diff -cr"

# file io
alias cp="cp -ir"
alias mv="mv -i"
alias rm="echo use \"trash\" instead or use \"/bin/rm -i\""

alias vi=vim

# network
alias route="route -n"

# process
alias ps="/bin/ps -U $(whoami) -o pid,bsdstart,state,rss,args -H"
alias psA="/bin/ps -A -o pid,bsdstart,state,rss,euser,args -H"

# disk
alias free="free -m"
alias df="df -h"
alias du="du -hs"


I have just tried this and still doesn't work:

/bin/ps | /bin/grep pts

Offline

#9 2012-03-26 08:32:47

Blµb
Member
Registered: 2008-02-10
Posts: 224

Re: [solved] pipe does not work?!

A quick rant against the first 2 replies: Read his OP again, he specifically stated that when '>' piping to a file and grepping the file, the output was correct, meaning it's diffrent from the | pipe, which it shouldn't be. There's no point in telling him that ps by default *probably* doesn't do what he expects.

Yesterday I had a problem with zsh, where: for i in `seq 1 100`; do X; done
would print the seq command to stdout rather than using it in the for loop.
I recompiled zsh from source and it worked - so there could be something broken int the binary package, or I just screwed something up elsewhere.

So, given my recent experiences, I'd ask you to try recompiling bash from source and see if it changes anything, even if that's not the way it's supposed to be done.
But if it helps, then the shell packages (or more likely what they commonly depend on) need checking...

Last edited by Blµb (2012-03-26 08:33:15)


You know you're paranoid when you start thinking random letters while typing a password.
A good post about vim
Python has no multithreading.

Offline

#10 2012-03-26 08:43:08

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: [solved] pipe does not work?!

Blµb wrote:

A quick rant against the first 2 replies: Read his OP again...

Perhaps, rather than ranting, you should read the thread again. The OP's problem -that he neglected to mention until his second post- is that he aliased `ps`

Little details like that matter.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#11 2012-03-27 02:55:06

bsdson.tw
Member
From: Taiwan
Registered: 2005-05-06
Posts: 161

Re: [solved] pipe does not work?!

Thanks, jasonwryan and Blµb!

I have made a quick exam by re-install bash
both "4.2.024-2" and "4.2.020-1",

but neither work.

I will try to compile it on my own and report the result later.

Thank you very much! smile

Offline

#12 2012-03-27 02:57:25

bsdson.tw
Member
From: Taiwan
Registered: 2005-05-06
Posts: 161

Re: [solved] pipe does not work?!

BTW,

may I ask...
is the function "pipe" provided by "bash" itself or by another program or another library (like... readline?)
or by some underlying IPC mechanism? memory sharing? socket?

Is there any other way I can diagnose the system?

BR,
Henry

Offline

#13 2012-03-27 04:13:09

bsdson.tw
Member
From: Taiwan
Registered: 2005-05-06
Posts: 161

Re: [solved] pipe does not work?!

failed to make bash...      o.O

configure: creating ./config.status
config.status: creating Makefile
config.status: creating builtins/Makefile
config.status: creating lib/readline/Makefile
config.status: creating lib/glob/Makefile
config.status: creating lib/intl/Makefile
config.status: creating lib/malloc/Makefile
config.status: creating lib/sh/Makefile
config.status: creating lib/termcap/Makefile
config.status: creating lib/tilde/Makefile
config.status: creating doc/Makefile
config.status: creating support/Makefile
config.status: creating po/Makefile.in
config.status: creating examples/loadables/Makefile
config.status: creating examples/loadables/perl/Makefile
config.status: creating config.h
config.status: executing default-1 commands
config.status: creating po/POTFILES
config.status: creating po/Makefile
config.status: executing default commands
bison -y -d ./parse.y
conflicts: 1 shift/reduce
touch parser-built
rm -f mksyntax
gcc  -DPROGRAM='"bash"' -DCONF_HOSTTYPE='"x86_64"' -DCONF_OSTYPE='"linux-gnu"' -DCONF_MACHTYPE='"x86_64-unknown-linux-gnu"' -DCONF_VENDOR='"unknown"' -DLOCALEDIR='"/usr/share/locale"' -DPACKAGE='"bash"' -DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -g  -o mksyntax ./mksyntax.c
In file included from ./mksyntax.c:25:0:
/usr/include/stdio.h:103:19: error: two or more data types in declaration specifiers
In file included from /usr/include/stdlib.h:320:0,
                 from ./bashansi.h:36,
                 from ./mksyntax.c:26:
/usr/include/sys/types.h:36:17: error: two or more data types in declaration specifiers
/usr/include/sys/types.h:36:17: error: two or more data types in declaration specifiers
/usr/include/sys/types.h:37:18: error: two or more data types in declaration specifiers
/usr/include/sys/types.h:37:18: error: two or more data types in declaration specifiers
/usr/include/sys/types.h:66:17: error: two or more data types in declaration specifiers
/usr/include/sys/types.h:71:18: error: two or more data types in declaration specifiers
/usr/include/sys/types.h:81:17: error: two or more data types in declaration specifiers
/usr/include/sys/types.h:99:17: error: two or more data types in declaration specifiers
In file included from /usr/include/sys/types.h:133:0,
                 from /usr/include/stdlib.h:320,
                 from ./bashansi.h:36,
                 from ./mksyntax.c:26:
/usr/include/time.h:60:19: error: two or more data types in declaration specifiers
/usr/include/time.h:76:18: error: two or more data types in declaration specifiers
In file included from /usr/include/sys/types.h:220:0,
                 from /usr/include/stdlib.h:320,
                 from ./bashansi.h:36,
                 from ./mksyntax.c:26:
/usr/include/sys/select.h:38:20: error: two or more data types in declaration specifiers
In file included from ./mksyntax.c:31:0:
/usr/include/unistd.h:275:21: error: two or more data types in declaration specifiers
make: *** [mksyntax] Error 1
==> ERROR: A failure occurred in build().
    Aborting...
[henry@henry_u59 bash]$

...

Offline

#14 2012-03-27 13:44:29

Blµb
Member
Registered: 2008-02-10
Posts: 224

Re: [solved] pipe does not work?!

bsdson.tw wrote:

(...)
is the function "pipe" provided by "bash" itself or by another program or another library (like... readline?)
(...)

By bash (as it is in any other shell I know of - often implemented by creating an unnamed pipe(2) and using dup2(2) to replace the first program's stdout and the second program's stdin.)

bsdson.tw:
Are you using makepkg in the package from core, or the sources directly?
Though the error doesn't look like it depends on that.

Do you have gcc or gcc-multilib. Which version / how up-to-date is your system in general?
Are your base-devel group and the build-time dependencies listed in bash's PKGBUILD up to date?

If so, check the header files it complains about (/usr/include/stdio.h), maybe there's some corruption in there?
(That could be fixable by reinstalling glibc)

EDIT:
Works for me, I have the following versions:

wry:~/ $ pacman -Qqi gcc gcc-libs glibc readline pacman make ncurses binutils-multilib |grep Version                                                [15:54:33]
Version        : 4.7.0-1
Version        : 4.7.0-1
Version        : 2.15-7
Version        : 6.2.002-1
Version        : 4.0.2-1
Version        : 3.82-4
Version        : 5.9-3
Version        : 2.22-4.1

Nevermind gcc 4.7, it should definitely work with the one in the current repo (4.6.3) or any other gcc... (haha... maybe not... I blame GNU if it doesn't tongue), also, it shouldn't make any difference that I have non-multilib gcc but binutils-multilib.

Last edited by Blµb (2012-03-27 13:55:56)


You know you're paranoid when you start thinking random letters while typing a password.
A good post about vim
Python has no multithreading.

Offline

#15 2012-03-28 09:26:44

bsdson.tw
Member
From: Taiwan
Registered: 2005-05-06
Posts: 161

Re: [solved] pipe does not work?!

Hi,

my system is quite up-to-date.

[henry@henry_u59 ~]$ pacman -Q gcc gcc-libs glibc readline pacman make ncurses lib32-gcc-libs readline binutils-multilib gcc 4.6.3-1
gcc-libs 4.6.3-1
glibc 2.15-7
readline 6.2.002-1
pacman 4.0.2-1
make 3.82-4
ncurses 5.9-3
lib32-gcc-libs 4.6.3-1
readline 6.2.002-1
error: package 'binutils-multilib' was not found
[henry@henry_u59 ~]$

and... according to your explaination of how "pipe" works,
may it related to the file system: "pts" "shm"?

I recently removed 2 entries in fstab to mount "pts" and "shm",
because I have heard those 2 has been handled in rc.sysinit...

ps. I have re-installed glibc and readline, but still can successfully make bash package.

Offline

#16 2012-03-28 09:34:03

bsdson.tw
Member
From: Taiwan
Registered: 2005-05-06
Posts: 161

Re: [solved] pipe does not work?!

I just found it probably related to some kind of permission problem...

because "pipe" works correctly in "root@console",
but not "me@x window terminal" nor "root@x window terminal"...

BR,
Henry

Offline

#17 2012-03-28 12:34:41

Blµb
Member
Registered: 2008-02-10
Posts: 224

Re: [solved] pipe does not work?!

You mean you can pipe as root in a console, but not as user/root in X?
Does it only affect ps | grep, or also other commands... 'echo aaa | cat' for example?
What shell are you using? Do root and your user use the same shell?
Do you have anything out of the ordinary installed? Any special permissions set?
Are you using selinux/apparmor/tomoyo?


You know you're paranoid when you start thinking random letters while typing a password.
A good post about vim
Python has no multithreading.

Offline

#18 2012-03-30 03:51:16

bsdson.tw
Member
From: Taiwan
Registered: 2005-05-06
Posts: 161

Re: [solved] pipe does not work?!

Blµb wrote:

You mean you can pipe as root in a console, but not as user/root in X?
Does it only affect ps | grep, or also other commands... 'echo aaa | cat' for example?
What shell are you using? Do root and your user use the same shell?
Do you have anything out of the ordinary installed? Any special permissions set?
Are you using selinux/apparmor/tomoyo?

<as root in console>
I can successfully execute following commands:

ps -Af | grep usr
echo abc | grep a
echo abc | cat

<as my daily-use account in console>
AND
<as my daily-use account in "terminal in x-win" >

I can only successfully execute this one:

echo abc | cat

but not these:

ps -Af | grep usr
echo abc | grep a

<as a newly created account in console>
can successfully execute all 3 commands

---------------------------------------------------------------
I use "bash" as the shell for all 3 accounts (root and the other two)
In my memory, I didnot set any special permission or touch any installation/setup.
and did not use selinux/apparmor/tomoyo.
(I have not even heard of apparmor and tomoyo, so I guess I did not use them)

BR,
Henry

Offline

#19 2012-03-30 08:40:44

skanky
Member
From: WAIS
Registered: 2009-10-23
Posts: 1,847

Re: [solved] pipe does not work?!

Have you tried with some other commands that accept stdin? At the moment your common denominator is | and grep. Try a

$ which grep

And just make sure you've not got some wrapper round grep that's preventing it receiving a stdin.


"...one cannot be angry when one looks at a penguin."  - John Ruskin
"Life in general is a bit shit, and so too is the internet. And that's all there is." - scepticisle

Offline

#20 2012-03-30 11:03:38

bsdson.tw
Member
From: Taiwan
Registered: 2005-05-06
Posts: 161

Re: [solved] pipe does not work?!

Dear all,

I have found the root cause,
which is the GREP_OPTIONS "--devices=skip".

After removing this option, everything works fine.
I guess it's due to recent upgrade of "grep" that changed the behavior...(?)

Thank you all very very much for your kindness to help me on this...
Thank you!

BR,
Henry

Offline

Board footer

Powered by FluxBB