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)的前提下,交互式 ...
随机推荐
- -O1 -O2 -O3 优化的原理是什么?
一般来说,如果不指定优化标识的话,gcc就会产生可调试代码,每条指令之间将是独立的:可以在指令之间设置断点,使用gdb中的 p命令查看变量的值,改变变量的值等.并且把获取最快的编译速度作为它的目标. ...
- Low-Code,一定“low”吗?
作者:京东保险 吴凯 前言 低代码是一组数字技术工具平台,基于图形化拖拽.参数化配置等更为高效的方式,实现快速构建.数据编排.连接生态.中台服务.通过少量代码或不用代码实现数字化转型中的场景应用创新. ...
- Java---->集合(上)
一.集合的框架 1.集合.数组都是对多个数据进行存储操作的结构,简称Java容器. * 说明:此时的存储,主要是指能存层面的存储,不涉及到持久化的存储(.txt,.jpg,.avi,数据库中) ...
- MYSQL5.7.30安装
1.下载MySQL 我用的是5.7.30(安装版) 我选择的下载链接:https://dev.mysql.com/downloads/windows/installer/5.7.html 官网链接:h ...
- flask快速上手
看完这2个基本可以起步flask了 一学习 https://www.codingdict.com/article/4884 二实战 https://blog.miguelgrinberg.com/po ...
- 【SSM项目】尚筹网(五)项目改写:使用前后端分离的SpringSecurityJWT认证
在项目中加入SpringSecurity 1 加入依赖 <!-- SpringSecurity --> <dependency> <groupId>org.spri ...
- 【Spring注解驱动】(三)Servlet 3.0
前言 今天是7.21日,终于是看完了..暑假在家学习是真的差点意思 1 Servlet 3.0简介 Servlet 2.0是在web.xml中配置servlet filter.listener.Dis ...
- AI时代下普通小程序员的想法
在我接触了一系列AI技术后,不禁产生了许多思考.我先后尝试了AI编程.AI写论文.AI写小说.AI绘画等,最近看到了一些关于AI构建虚拟世界以及Auto-GPT的AI类新闻.在这个过程中,我心头涌现出 ...
- Active Record Associations
The Types of Associations 在 Rails 中,可以通过 ActiveRecord 来定义不同类型的关联关系(Associations),包括以下几种: belongs_to: ...
- Unix shell开头的#!
1:位于脚本文件最开始 2:#!告诉系统内核应有哪个shell来执行所指定的shell脚本. 3:如#! /bin/bash ,#!与shell文件名之间可以有空格,没有限定. 4:指定的shell可 ...