有关Linux进程与线程数目计算的问题
来源:互联网 发布:毕向东java视频怎么样 编辑:程序博客网 时间:2024/05/21 15:18
问题的提出:
Linux,一个进程有n个线程,每个线程又使用fork()创建了一个进程?
请问:总共有多少线程和进程?
问题的解答:
Alexander Amelkin • According to POSIX, after a fork() only the calling thread is to be cloned and all thread-related entities are not guaranteed to work (and in fact will NOT work). POSIX has a list of functions that are safe to use after fork() and most of the thread-related functions aren't on that list. Actually, there is a good explanation given in the Rationale section of the fork() description in POSIX1. In a few words, it says that fork() in a threaded application is only truly safe to use when it is almost immediately followed by exec().
Now, to answer your question. There will be your process with n threads plus n processes with 1 thread each. That totals n+1 processes and 2*n threads.
Yuri Perepechkin •http://pubs.opengroup.org/onlinepubs/009695399/functions/fork.html
fork - create a new process
A process shall be created with a single thread.
the new process shall contain a replica of the calling thread
Process/Threads:
* --fork-> 1/1
...
* --fork-> n-1/1
* --fork-> n/1
Total
processes: 1+n
threads: n+(n*1)=2n
Assumed each process must have one thread at least (main thread)
Start thread and process numeration from 1.
Daya Shanker Prasad •Thank you all, for your answer. For a long time I used to think about it but couldn't pay time on this. Finally I experimented this and got:
Thread: 2n + 1
Process: n + 1
main() was running as separate thread which was forking n threads.
- 有关Linux进程与线程数目计算的问题
- 查询进程的线程数目
- linux系统中进程的最大线程数目
- Android中Service与Activity的有关于进程与线程的问题
- Android中Service与Activity的有关于进程与线程的问题
- linux中有关僵尸进程的问题
- linux中有关僵尸进程的问题
- linux运维-与进程有关的命令
- 有关线程与进程的基础与理解
- Linux的进程与线程
- linux的进程与线程
- Linux的进程与线程
- linux的进程与线程
- 线程 进程最大数目
- 有关进程,线程通信的几个详细问题
- 计算几何与圆心和球有关的计算问题
- [计算力] 苹果的数目问题
- nginx的worker数目进程设置问题
- 音乐舞蹈游戏-LGame
- poj 1579(记忆化搜索)DP
- 【Kris专题】android 换肤
- 怎样利用C语言编程获得本机的IP地址
- 一个简单入门的win32 socket程序
- 有关Linux进程与线程数目计算的问题
- C++ 获取整数各位数字
- vmware esx 5.0高可用之一dpm
- 【kris专题】android 换肤(续)
- 文档手册中心
- 将二叉树的两个孩子换位置,即左变右,右变左。(递规与非递规两种方法)
- Web Service Study notes
- 运维相关知识
- ubuntu 添加自启动脚本