线程问题——同样的程序,在ubuntu中运行和嵌入式中PID表现不同的原因

 

1. 同一多线程程序,经过编译和交叉编译后,在ubuntu和在我们的ARM板的嵌入式LINUX中运行时候,通过ps 看到的信息不一致:
   比如:同样的attr_thread这个程序:
   ubuntu中运行后,通过ps -aux只能看到一个进程在运行
   目标板中运行后,通过ps 能看到4个进程在运行,但运行的程序名字是一致的

原因:
   ubuntu中使用NPTL线程库,目标板中使用linuxthreads线程库
  
   NPTL从一个进程中所有的线程中运行getpid()获取到得PID值相同
   而linuxthreads每个线程使用不同的PID,从一个进程中不同线程中运行getpid()获取到得PID值不相同

2. 确认系统中线程库是那一种的方法:

   查看方法可以通过运行/lib/libc.so.6 可看到:
 
ubuntu中如下:
  shyi@ubuntu:~/labs/1106/labs/threads$ /lib/libc.so.6
GNU C Library (Ubuntu EGLIBC 2.12.1-0ubuntu6) stable release version 2.12.1, by Roland McGrath et al.
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.4.5 20100909 (prerelease).
Compiled on a Linux 2.6.35 system on 2010-09-10.
Available extensions:
        crypt add-on version 2.1 by Michael Glad and others
        GNU Libidn by Simon Josefsson
        Native POSIX Threads Library by Ulrich Drepper et al  (这一行是重点,表示这是NPTL)
        BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<http://www.debian.org/Bugs/>.


目标板上:
# /lib/libc.so.6
GNU C Library stable release version 2.3.6, by Roland McGrath et al.
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 3.4.5.
Compiled on a Linux 2.6.12 system on 2008-09-10.
Available extensions:

        GNU libio by Per Bothner
        crypt add-on version 2.1 by Michael Glad and others
        linuxthreads-0.10 by Xavier Leroy  (这一行是重点,表示这是linuxthreads)                   
        BIND-8.2.3-T5B
        libthread_db work sponsored by Alpha Processor Inc
        NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值