Distinction between processes and threads in Linux

后端 未结 3 1874
甜味超标
甜味超标 2020-12-02 17:48

After reading up on this answer and \"Linux Kernel Development\" by Robert Love and, subsequently, on the clone() system call, I discovered that processes and t

3条回答
  •  死守一世寂寞
    2020-12-02 18:05

    Imagine some sort of "meta-entity". If the entity shares none of the resources (address space, file descriptors, etc) of its parent then it's a process, and if the entity shares all of the resources of its parent then it's a thread. You could even have something half-way between process and thread (e.g. some resources shared and some not shared). Take a look at the "clone()" system call (e.g. http://linux.die.net/man/2/clone ) and you'll see this is how Linux does things internally.

    Now hide that behind some sort of abstraction that makes everything look like either a process or a thread. If the abstraction is flawless you'd never know the difference between "entities" and "processes and threads". The abstraction isn't quite flawless though - the PID you're seeing is actually an "entity ID".

提交回复
热议问题