When executing ps command in my Linux system i see some user processes twice (different PID...). I wonder if they are new processes or threads of the same process. I know some functions in standard C library that could create a new process such fork(). I wonder what concrete functions can make a process appear twice when i execute ps command because i am looking in the source code where the new process or thread is created.

  • Can you post output of ps -fLa? – Karlson Nov 26 '13 at 14:11
  • my version of ps accepts no option (busybox ps in embedded device). – MABC Nov 26 '13 at 14:18
  • In Linux, threads are LWP (light-weight processes). Other version of *nix may be different. – jordanm Nov 26 '13 at 17:24

Little bit confusing. fork is a system call which creates a new process by copying the parent process' image. After that if child process wants to be another program, it calls some of the exec family system calls, such as execl. If you for example want to run ls in shell, shell forks new child process which then calls execl("/bin/ls").

If you see two programs and their pid's are different, check their ppid's (parent id's). For example, if p1 is ppid of process whose pid is p2, it means that process whose id is p1 forked that process. But if first process' ppid is not same that the other process' pid, it means that the same command is executed twice.

If pid and ppid are same, but tid's (thread id's) are different, it means that it's one process that has 2 threads.

I think that making your own shell is a good start point.

  • Threads have different PID in my system, so it depends of C library and kernel. – MABC Nov 26 '13 at 23:31

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.