ndk std_thread 获取pid
本文链接
https://www.cnblogs.com/wanger-sjtu/p/16817532.html
最近在解决tvm绑核问题时,发现android下绑核只有sched_setaffinity函数,这导致无法使用标准库中的td::thread::native_handle_type thread 进行绑核操作。虽然在ndk 21以上的版本提供了pthread_gettid_np函数获取线程相应的pid,但在较低版本中,还是没办法直接使用。
看下ndk 中 std 标准库上thread 的实现。
class _LIBCPP_TYPE_VIS thread
{
__libcpp_thread_t __t_;
...
public:
typedef __thread_id id;
typedef __libcpp_thread_t native_handle_type;
...
};
typedef pthread_t __libcpp_thread_t;
typedef long pthread_t;
上面可以看出,在ndk的实现中native_handle_type 等价于pthread_t, 再根据pthread_gettid_np的实现,可以发现 ,pthread_t 其实就是pthread_internal_t的地址。在pthread_internal_t中保存了线程的tid
pid_t pthread_gettid_np(pthread_t t) {
return __pthread_internal_gettid(t, "pthread_gettid_np");
}
pid_t __pthread_internal_gettid(pthread_t thread_id, const char* caller) {
pthread_internal_t* thread = __pthread_internal_find(thread_id, caller);
return thread ? thread->tid : -1;
}
typedef struct pthread_internal_t
{
struct pthread_internal_t* next;
struct pthread_internal_t* prev;
pthread_attr_t attr;
pid_t tid;
bool allocated_on_heap;
pthread_cond_t join_cond;
int join_count;
void* return_value;
int internal_flags;
__pthread_cleanup_t* cleanup_stack;
void** tls; /* thread-local storage area */
/*
* The dynamic linker implements dlerror(3), which makes it hard for us to implement this
* per-thread buffer by simply using malloc(3) and free(3).
*/
#define __BIONIC_DLERROR_BUFFER_SIZE 512
char dlerror_buffer[__BIONIC_DLERROR_BUFFER_SIZE];
} pthread_internal_t;
ndk std_thread 获取pid的更多相关文章
- 获取Pid
Java程序中获取当前进程的进程ID 标签: javainterfacesystemcompilationjvmjni 2011-12-29 16:31 15182人阅读 评论(2) 收藏 举报 分 ...
- 根据PID获取进程名&根据进程名获取PID
Liunx中 通过进程名查找进程PID可以通过 pidof [进程名] 来查找.反过来 ,相同通过PID查找进程名则没有相关命令.在linux根目录中,有一个/proc的VFS(虚拟文件系统),系统当 ...
- python 通过js控制滚动条拉取全文 通过psutil获取pid窗口句柄,通过win32gui使程序窗口前置 通过autopy实现右键菜单和另存为操作
1.参考 利用 Python + Selenium 自动化快速截图 利用 Python + Selenium 实现对页面的指定元素截图(可截长图元素) 使用python获取系统所有进程PID以及进程名 ...
- linux下根据进程名字获取PID,类似pidof(转)
linux有一个命令行工具叫做pidof,可以根据用户输入的进程名字查找到进程号,但有时候我们需要在程序里实现,不想调用system,在查阅了很多版本的pidof源代码后,没有发现一个自己感觉比较好的 ...
- linux根据进程名获取PID
经常需要Kill多个进程,这些进程包含共同的关键字,可以用一条命令Kill掉它们. ps aux | grep "common" |grep -v grep| cut -c 9-1 ...
- Bash Shell 获取进程 PID
转载地址:http://weyo.me/pages/techs/linux-get-pid/ 导读 Linux 的交互式 Shell 与 Shell 脚本存在一定的差异,主要是由于后者存在一个独立的运 ...
- linux shell 获取进程pid
1.通过可执行程序的程序名称 a.运行程序 b.获取进程id号 c.pidof相关知识:http://www.cnblogs.com/yunsicai/p/3675938.html 2.有些程序需要在 ...
- CMD魔法堂:获取进程路径和PID值的方法集
一.前言 在开发发布更更新工具——更新Weblogic应用模块时,了解到更新Weblogic应用需要先关闭Weblogic应用窗口然后是清缓存.更新应用文件,最后再重启Weblogic应用窗口. ...
- linux命令(26):Bash Shell 获取进程 PID
转载地址:http://weyo.me/pages/techs/linux-get-pid/ 根据pid,kill该进程:http://www.cnblogs.com/lovychen/p/54113 ...
- 014-交互式Shell和shell脚本获取进程 pid
Linux 的交互式 Shell 与 Shell 脚本存在一定的差异,主要是由于后者存在一个独立的运行进程 1.交互式 Bash Shell 获取进程 pid 在已知进程名(name)的前提下,交互式 ...
随机推荐
- 准确率、召回率及AUC概念分析
准确率&&召回率 信息检索.分类.识别.翻译等领域两个最基本指标是准确率(precision rate)和召回率(recall rate),准确率也叫查准率,召回率也叫查全率.这些概念 ...
- YUM下载全量依赖
在离线的内网环境下进行安装一些软件的时候会出现依赖不完整的情况,一般情况下会使用如下方式进行下载依赖包 查看依赖包可以使用 yum deplist 进行查找 [root@localhost ~]# y ...
- kubernetes核心实战(三)--- ReplicationController
5.ReplicationController ReplicationController 确保在任何时候都有特定数量的 Pod 副本处于运行状态.换句话说,ReplicationController ...
- [Linux]异常配置专题之重复配置的有效性:系统/环境变量 | hosts
1 文由 在项目中经常遇到这种情况,1个hosts文件里同一IP 或 域名存在多个映射配置,那么到底哪个有效?环境变量亦有此问题. 问题本身不难,只是为了避免混淆,进行专门记录,以加深记忆. 2 ho ...
- Kubernetes客户端认证——基于CA证书的双向认证方式
1.Kubernetes 认证方式 Kubernetes集群的访问权限控制由API Server负责,API Server的访问权限控制由身份验证(Authentication).授权(Authori ...
- Go Home
Go Home (https://www.luogu.com.cn/problem/AT_arc070_a) 比较需要理解题意的一个题目 看看题目解析:在0秒的时候有一只袋鼠在左右无限长的数轴上的原点 ...
- 20-优化配置介绍、HMR
webpack性能优化 开发环境性能优化 生产环境性能优化 开发环境性能优化 优化打包构建速度 HMR 优化代码调试 source-map 生产环境性能优化 优化打包构建速度 oneOf babel缓 ...
- Centos7.x 更换Jenkins构建目录
原由:最近因为原来的Jenkins构建目录,已经要满了,想着更换下构建目录,此篇文件简单介绍下更换过程. 注:此文章可能仅适用于我个人,仅供参考.如有其他办法,欢迎评论指教. 查了几种方法,最终选为使 ...
- 网络编程之java简易聊天室实现
最近浅学习了一些关于网络编程方面的知识,视频是跟着狂神学习的,可能学习的不是很深 说到网络,相信大家都对TCP.UDP和HTTP协议这些都不是很陌生,学习这部分应该先对端口.Ip地址这些基础知识有一定 ...
- 浅谈ArrayList和LinkedList
文章目录 前言 ArrayList和LinkedList List的方法 ArrayList add remove LinkedList remove get和peek push ArrayList和 ...