I'm executing the following ps command:

root@dor-desktop:/home/dor# ps u -t "$(tty)" -u mysql
dor       2070  0.0  0.1  22436  5240 pts/0    Ss   20:29   0:00 bash
root      2411  0.0  0.0  56028  1916 pts/0    S    20:45   0:00 su
root      2419  0.0  0.0  19532  2276 pts/0    S    20:45   0:00 bash
root      2488  0.0  0.0   4108   668 pts/0    S    20:51   0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --skip-networking --skip-grant-tables --user=mysql --b
mysql     2607  0.0  0.4 146552 19024 pts/0    Sl   20:51   0:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/var --use
root      2672  0.0  0.0  15268  1224 pts/0    R+   20:59   0:00 ps u -t /dev/pts/0 -u mysql

You can see that the command asks for processes who are associated with the current terminal and who's user is mysql. But I get both types of processes!

How can I separate? I want only the process who initiated by the user mysql.

I found the following command: ps -C mysqld, which gives me want I need, but I prefer to understand what's wrong with the first command.

  • Are you sure mysql is the user name, and not some variation thereof? and have you the EUID in place of the name? – demure Jun 1 '13 at 18:17
  • I just replicated this on OSX, except I got ps: illegal argument: mattdmo when I put my username as the value after -u. If I put nothing after -u then I got a result similar to @Dor. This is using the BSD version of ps – MattDMo Jun 1 '13 at 18:22
  • 1
    @Dor what OS are you running, and where did your version of ps originate? I just ran your original command on Fedora 18 (GNU coreutils) and it worked exactly as expected - it only showed the processes associated with the user specified by -u – MattDMo Jun 1 '13 at 18:25

But I get both types of processes!

Quite surprising, considering that the man page says:

Except as described below, process selection options are additive. The default selection is discarded, and then the selected processes are added to the set of processes to be displayed. A process will thus be shown if it meets any of the given selection criteria.

| improve this answer | |
  • Irony doesn't work too well... – a CVn Jun 1 '13 at 20:01

As HaukeLagin explained, that's normal. An easy way around it is to parse the ps output:

ps u -t "$(tty)" | gawk '$1 == "mysql" || $1 == "USER"' 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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