linux 概念之pid tid区分
来源:互联网 发布:js copy对象 编辑:程序博客网 时间:2024/06/06 05:52
以前对linux下的线程id,进程id,真实线程id理解不够。自己记录一下。
linux下查看pid和tid的命令:
进程pid: getpid()
线程tid: pthread_self() //进程内唯一,但是在不同进程则不唯一。
线程pid: syscall(SYS_gettid) //系统内是唯一的
不同进程中创建线程,可能线程tid相同
#include <stdio.h>#include <pthread.h>#include <sys/types.h>#include <sys/syscall.h>struct message{ int i; int j;};void *hello(struct message *str){ printf("child, the tid=%lu, pid=%d\n",pthread_self(),syscall(SYS_gettid)); printf("the arg.i is %d, arg.j is %d\n",str->i,str->j); printf("child, getpid()=%d\n",getpid()); while(1);}int main(int argc, char *argv[]){ struct message test; pthread_t thread_id; test.i=10; test.j=20; pthread_create(&thread_id,NULL,hello,&test); printf("parent, the tid=%lu, pid=%d\n",pthread_self(),syscall(SYS_gettid)); printf("parent, getpid()=%d\n",getpid()); pthread_join(thread_id,NULL); return 0;}
参考:http://blog.csdn.net/u012398613/article/details/52183708
0 0
- linux 概念之pid tid区分
- Linux pid tid说明
- linux中的pid与tid
- Linux下线程pid和tid
- Linux下线程pid和tid
- linux中pid,tid, 以及 真实pid的关系
- linux中pid,tid, 以及 真实pid的关系
- Linux proc/pid/task/tid/stat文件详解
- Linux proc/pid/task/tid/stat文件详解
- linux中pid gid tgid tid的区别和联系
- Linux proc/pid/task/tid/stat文件详解
- The Linux Process Principle, PID、PGID、PPID、SID、TID、TTY
- 查看进程pid/tid
- linux常见问题之系统移植的概念区分
- Android中的PID,UID,TID
- android中的Uid、Pid、Tid
- android中的Uid、Pid、Tid
- Linux C++中获取指定pid、tid的CPU与内存占用信息
- TFTP&NFS 的配置
- 解决头文件定义变量的问题,巧用宏定义(续)
- 工厂模式
- IO流
- install hadoop in fedora
- linux 概念之pid tid区分
- php实现自动加载类
- C++STL之String详解
- 简单算法
- Cogs 763. [USACO Open09] 数字的游戏(博弈)
- 使用 JavaScript 下载文件
- 图像定位(一)、坐标变换
- 占整个屏的设计,滑动
- Hungarian method (匈牙利算法)----解决指派问题(转)