Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

When I run top -H, I see that my multiple mysql threads all have the same PID. However, in ps -eLf I see each one has a different PID:

ps -eLf

UID        PID  PPID   LWP  C NLWP STIME TTY          TIME CMD
mysql     1424     1  1424  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1481  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1482  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1483  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1484  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1485  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1486  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1487  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1488  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1489  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1490  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1791  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1792  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1793  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1794  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1809  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld
mysql     1424     1  1812  0   17 18:41 ?        00:00:00 /usr/sbin/mysqld

and in top -H

PID USER      PR  NI  VIRT  RES  SHR S  %CPU %MEM    TIME+  COMMAND
 1424 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.08 mysqld                                                                  
 1481 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.16 mysqld                                                                  
 1482 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.33 mysqld                                                                  
 1483 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.16 mysqld                                                                  
 1484 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.23 mysqld                                                                  
 1485 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.27 mysqld                                                                  
 1486 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.15 mysqld                                                                  
 1487 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.18 mysqld                                                                  
 1488 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.16 mysqld                                                                  
 1489 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.16 mysqld                                                                  
 1490 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.34 mysqld                                                                  
 1791 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.26 mysqld                                                                  
 1792 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.54 mysqld                                                                  
 1793 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.00 mysqld                                                                  
 1794 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.00 mysqld                                                                  
 1809 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.00 mysqld                                                                  
 1812 mysql     20   0  539m  56m 7200 S   0.0  1.5   0:00.13 mysqld

What is going on and which one should I believe?

share|improve this question
    
Where is the question ? –  Vinz Nov 28 '13 at 14:44

3 Answers 3

up vote 3 down vote accepted

They are actually showing the same information in different ways. This is what the -f and -L options to ps do (from man ps, emphasis mine):

-f               Do full-format listing. This option can be combined with many other UNIX-style options                   to add additional columns. It also causes the command arguments to be printed. When                   used with -L, the NLWP (number of threads) and LWP (thread ID) columns will be                   added. See the c option, the format keyword args, and the format keyword comm.

-L              Show threads, possibly with LWP and NLWP columns.                    

lwp             LWP light weight process (thread) ID of the dispatchable entity (alias spid, tid). See tid                    for additional information.                    

tid              TID the unique number representing a dispatacable entity (alias lwp, spid). This value                   may also appear as: a process ID (pid); a process group ID (pgrp); a session ID for the                   session leader (sid); a thread group ID for the thread group leader (tgid); and a tty                   process group ID for the process group leader (tpgid).

So, ps will show thread IDs in the LWP column while the PID column is the actual process identifier.

top on the other hand, lists the different threads in the PID column though I can't find an explicit mention of this in man top.

share|improve this answer

It's just a difference in presentation. Look at the LWP column on your ps output -- LWP is LightWeight Process. The kernel can distinguish between a full process and a thread, but it still has to schedule them independently (that being the purpose of a thread) with the same mechanism it uses to schedule processes and so the id's the scheduler sees have to be unique, best achieved by having a single pool of process and thread id's for every purpose and using other ways to tell the two kinds apart.

share|improve this answer

You see the parent process 1424, a process that has created one or more child processes (the other PIDs).

share|improve this answer
    
They aren't child processes, they're kernel threads of the same process. –  Gilles Nov 28 '13 at 23:27

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.