免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 4610 | 回复: 13
打印 上一主题 下一主题

单进程变成了多进程,百思不得其解? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-18 13:20 |只看该作者 |倒序浏览
我在ES4.0上运行一个单进程的程序,用ps命令查看却出现很多个同名却不同PID的进程(我能确保我的程序是单进程,但是是多线程的程序),百思不得其解,盼回复!

具体的截图如下:
[starnvsm@Bs log]$ ps aux|grep bs
starnvsm 22654  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:21 ./bs-test2
starnvsm 22655  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22656  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22658  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22659  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22660  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22661  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22662  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22663  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22664  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22665  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22666  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22667  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22668  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22669  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22670  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22671  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22672  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22673  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22674  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22675  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22676  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22677  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22678  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22679  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22680  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22681  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22682  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22683  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22684  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22685  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22686  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22687  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm 22688  0.0  1.4 116768 30964 pts/2  S+   Apr17   0:00 ./bs-test2
starnvsm  1528  0.0  0.0  6240  728 pts/4    S+   13:04   0:00 grep bs
[starnvsm@Bs log]$

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
2 [报告]
发表于 2008-04-18 13:26 |只看该作者
进程就是线程。

论坛徽章:
0
3 [报告]
发表于 2008-04-18 13:34 |只看该作者

论坛徽章:
0
4 [报告]
发表于 2008-04-18 13:34 |只看该作者

回复 #2 flw 的帖子

此言怎讲?我在别的系统上运行就是一个,从没出现这种就情况?

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
5 [报告]
发表于 2008-04-18 13:39 |只看该作者
原帖由 ljok30 于 2008-4-18 13:34 发表
此言怎讲?我在别的系统上运行就是一个,从没出现这种就情况?

有的 ps 命令确实能看到线程。
我很早以前也用过这样的 ps 命令。
这个和 ps 命令有关系。

论坛徽章:
0
6 [报告]
发表于 2008-04-18 13:44 |只看该作者

回复 #5 flw 的帖子

ps --version的结果也是一样,在两个相同内核的ES4.0上,表现就不一样?
procps version 3.2.3
我怀疑是环境配置问题,但是有没有确切证据!
另:在别的地方看到跟gcc的-static有关系,但是我的程序关键都是一样的阿,没道理啊?

招聘 : c/c++研发
论坛徽章:
0
7 [报告]
发表于 2008-04-18 15:08 |只看该作者
linux系统内核中无论是进程还是线程都是用一个task_struct结构表示,所不同的是各个进程的task_struct有自己独立的资源,而同一进程内的task_struct(线程)共享一些相同的资源(如进程地址空间等)。ps的功能只是遍历系统的task_struct列表并输出各个结构体相关的信息,所以你用ps的时候会发现线程表现的跟进程一个样

论坛徽章:
0
8 [报告]
发表于 2008-04-18 17:09 |只看该作者
linux有两种线程模型LinuxThreads 和 NPTL,可以看看下面的文章。
http://www.ibm.com/developerworks/cn/linux/l-threading.html

可以通过getconf GNU_LIBPTHREAD_VERSION获取当前使用线程模型版本
楼主机器使用的应该是LinuxThreads。

论坛徽章:
0
9 [报告]
发表于 2008-04-21 13:09 |只看该作者

回复 #8 Sorehead 的帖子

非常感谢Sorehead的回复,确实如你所说,一个是LinuxThreads,另一个是NPTL,非常感谢!
但是要怎么修改设置才能把LinuxThreads换成NPTL呢?

论坛徽章:
0
10 [报告]
发表于 2008-04-21 13:33 |只看该作者
从那个帖子可以看出线程库是glibc的一部分,因此换掉glibc应该就可以了。

不过我没有这么做过,具体操作方法就不知道了。
官方网站上应该有各种版本的glibc,可以找源代码下来编译安装,或者直接找rpm包或apt-get。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP