- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我需要为 Linux 提供 P/Invoke 签名 sched_setaffinity
函数,从在 Mono 上运行的 C# 代码调用。
int sched_setaffinity(pid_t pid, size_t cpusetsize,
cpu_set_t *mask);
ThreadAffinity
“open-hardware-monitor”项目中的类将其定义为:
[DllImport(LIBC)]
public static extern int sched_setaffinity(int pid, IntPtr maskSize,
ref ulong mask);
然而,Mono.LibRt项目使用不同的签名:
[DllImport (LIBC, CallingConvention=CallingConvention.Cdecl,
SetLastError=true, EntryPoint="sched_setaffinity")]
protected static extern int sched_setaffinity (long pid, int num_bytes,
byte[] affinity);
两个签名都正确,还是一个错误?它们是否可以跨 32 位和 64 位架构移植?
我假设第一个参数应该是 int
,而不是 long
,因为 pid_t
在 32-和 64 位平台(根据 Joe Shaw )。同样,根据 Patrick McDonald,第二个应该是 UIntPtr
或 IntPtr
.但是,我不知道如何处理第三个参数。
编辑:基于 Simon Mourier 的评论:我从 cpu_set_t *
类型中了解到,第三个参数应该是一个指针。 ref ulong
符合条件吗?我很想使用那种类型,因为它使宏更容易实现;例如,单个处理器 id
的掩码可以计算为:
ulong mask = 1UL << id;
我在 sched.h
中找到了 cpu_set_t
的定义,它作为 unsigned long int
数组实现。
最佳答案
如您所见,cpu_set_t 只是一个 unsigned long int 数组。所以我会这样声明函数:
[DllImport("libc.so.6", SetLastError=true)]
private static extern int sched_setaffinity(
int pid,
IntPtr cpusetsize,
ulong[] cpuset
);
关于c# - sched_setscheduler 的 P/Invoke 签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17118251/
如何使用此 topic 中解释的 sched_setscheduler ?看来我得写个C代码,在shell上运行? 最佳答案 要从 shell 更改进程的策略,您需要使用 chrt .要选择实时优先级
我有以下源,它喜欢 SCHED_RR 优先级 90: int main(int argc, char** argv) { const char *sched_policy[] = {
我是操作系统编程新手。因此,我编写了这段代码来更改后台进程的调度策略,我通过命令行参数提供了其进程 ID,但 sched_setscheduler() 函数失败,给出错误“函数未实现” #includ
我对 sched_setscheduler() 在 Linux 中的工作方式感到困惑。 我的理解是 Linux 在内部使用 CFS (SCHED_NORMAL) 进行内核进程调度。当用户空间启动一个程
我有一个调用 sched_setscheduler(pid, SCHED_RR, ... ) 的 C++ 应用程序。 该应用程序以 root 权限在 Linux 上运行。通话通常有效。只有在一个特定的
为什么 sched_setscheduler() 需要根权限? 我正在编写一些受益于设置 SCHED_FIFO 的代码。但是如果我使用 sched_setscheduler() 我现在必须要求这个进程
以下代码有效并需要“root”身份验证: struct sched_param param; param.sched_priority = 99; if (sched_setscheduler(0,
我需要为 Linux 提供 P/Invoke 签名 sched_setaffinity函数,从在 Mono 上运行的 C# 代码调用。 int sched_setaffinity(pid_t pid,
只是尝试使用 SCHED_FIFO 策略将调度优先级设置为最大。在我安装 libpam-systemd 后,这段代码开始抛出错误。 编辑:归结为下面的两个问题,尽可能把它们说清楚。 追踪: sched
我是一名优秀的程序员,十分优秀!