Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I run ps fax|grep grep it shows one process like:

 2618 pts/0    R+     0:00              \_ grep --color=auto grep

That would be OK, but when I run ps fax|grep -v dummy_text grep process isn't on the list!

  PID TTY      STAT   TIME COMMAND
    2 ?        S      0:00 [kthreadd]
    3 ?        S      0:02  \_ [ksoftirqd/0]
    5 ?        S      0:00  \_ [kworker/u:0]
    6 ?        S      0:00  \_ [migration/0]
    7 ?        S<     0:00  \_ [cpuset]
    8 ?        S<     0:00  \_ [khelper]
    9 ?        S<     0:00  \_ [netns]
   10 ?        S      0:00  \_ [sync_supers]
   11 ?        S      0:00  \_ [bdi-default]
   12 ?        S<     0:00  \_ [kintegrityd]
   13 ?        S<     0:00  \_ [kblockd]
   14 ?        S<     0:00  \_ [kacpid]
   15 ?        S<     0:00  \_ [kacpi_notify]
   16 ?        S<     0:00  \_ [kacpi_hotplug]
   17 ?        S<     0:00  \_ [ata_sff]
   18 ?        S      0:00  \_ [khubd]
   19 ?        S<     0:00  \_ [md]
   20 ?        S      0:00  \_ [khungtaskd]
   22 ?        S      0:00  \_ [kswapd0]
   23 ?        SN     0:00  \_ [ksmd]
   24 ?        S      0:00  \_ [fsnotify_mark]
   25 ?        S<     0:00  \_ [aio]
   26 ?        S      0:00  \_ [ecryptfs-kthrea]
   27 ?        S<     0:00  \_ [crypto]
   31 ?        S<     0:00  \_ [kthrotld]
   32 ?        S      0:00  \_ [kworker/0:1]
   33 ?        S      0:00  \_ [scsi_eh_0]
   34 ?        S      0:00  \_ [scsi_eh_1]
   35 ?        S      0:00  \_ [kworker/u:2]
   37 ?        S<     0:00  \_ [kmpathd]
   38 ?        S<     0:00  \_ [kmpath_handlerd]
   39 ?        S<     0:00  \_ [kondemand]
   40 ?        S<     0:00  \_ [kconservative]
   41 ?        S      0:00  \_ [kworker/0:2]
  172 ?        S      0:00  \_ [scsi_eh_2]
  185 ?        S<     0:00  \_ [kdmflush]
  198 ?        S<     0:00  \_ [kdmflush]
  206 ?        S      0:00  \_ [jbd2/dm-0-8]
  207 ?        S<     0:00  \_ [ext4-dio-unwrit]
  447 ?        S<     0:00  \_ [kpsmoused]
 2357 ?        S      0:00  \_ [flush-251:0]
    1 ?        Ss     0:00 /sbin/init
  181 ?        S      0:00 /lib/udev/watershed sh -c /sbin/lvm vgscan; /sbin/lvm vgchange -a y
  182 ?        S      0:00  \_ sh -c /sbin/lvm vgscan; /sbin/lvm vgchange -a y
  184 ?        S<L    0:00      \_ /sbin/lvm vgchange -a y
  258 ?        S      0:00 upstart-udev-bridge --daemon
  266 ?        S<s    0:00 udevd --daemon
  433 ?        S<     0:00  \_ udevd --daemon
  434 ?        S<     0:00  \_ udevd --daemon
  365 ?        Sl     0:00 rsyslogd -c4
  436 ?        Ss     0:00 dhclient3 -e IF_METRIC=100 -pf /var/run/dhclient.eth0.pid -lf /var/lib/dhcp3/dhclient.eth0.leases eth0
  473 ?        Ss     0:00 /usr/sbin/sshd -D
  828 ?        Ss     0:00  \_ sshd: censored_user [priv]
  850 ?        S      0:00  |   \_ sshd: censored_user@notty
  851 ?        Ss     0:00  |       \_ /usr/lib/openssh/sftp-server
 2369 ?        Ss     0:00  \_ sshd: censored_user [priv]
 2395 ?        S      0:00      \_ sshd: censored_user@pts/0
 2396 pts/0    Ss     0:01          \_ -bash
 2622 pts/0    R+     0:00              \_ ps fax
  511 ?        S      0:00 upstart-socket-bridge --daemon
  587 tty4     Ss+    0:00 /sbin/getty -8 38400 tty4
  590 tty5     Ss+    0:00 /sbin/getty -8 38400 tty5
  593 tty2     Ss+    0:00 /sbin/getty -8 38400 tty2
  594 tty3     Ss+    0:00 /sbin/getty -8 38400 tty3
  596 tty6     Ss+    0:00 /sbin/getty -8 38400 tty6
  602 ?        Ss     0:00 cron
  603 ?        Ss     0:00 atd
  826 tty1     Ss+    0:00 /sbin/getty -8 38400 tty1

How is that possible?

share|improve this question
    
sshd: censored_user. Paranoia? :) –  grawity Sep 1 '11 at 12:32
    
@grawity: Better safe than sorry :P –  Matej Sep 1 '11 at 12:39

1 Answer 1

up vote 2 down vote accepted

The -v option to grep tells it to only display lines not containing given text. The ps output line contains dummy_text, which is skipped. In other words, you simply told grep to ignore itself.

share|improve this answer
    
sure, but I told grep not to display lines containing "dummy_text", so where is grep? –  Matej Sep 1 '11 at 12:11
2  
@Matej: The grep line itself contains "dummy_text". (More precisely, "grep -v dummy_text".) –  grawity Sep 1 '11 at 12:12
    
oh, I am dumb, thanks! –  Matej Sep 1 '11 at 12:14
    
Hm are your sure that's the correct answer? I don't think ps will take into account parameters passed to the process. I think the right answer is that ps is executed before grep and thus grep should not show. Please correct me if I'm wrong! –  m0skit0 Sep 1 '11 at 12:23
1  
@m0skit0: As you can see from example #1 in the question, ps does show grep, since they are executed at more or less the same time (grep is already running when ps begins iterating the process list). Also, ps does show arguments when any of f, a, or x are given. –  grawity Sep 1 '11 at 12:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.