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.
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
If you see two programs and their
pid's are different, check their
ppid's (parent id's). For example, if
ppid of process whose
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.
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.