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

2019-07-13 06:25发布

  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>.