首页 > 解决方案 > 来自 Cython 的 syscall 或 gettid 系统函数

问题描述

我需要gettid从 Cython 打电话。根据其手册页,我应该使用该syscall功能。我正在运行 Linux。

我可以很容易地得到gettid函数号:

cdef extern from "sys/syscall.h":
    cdef int __NR_gettid

但我找不到如何导入或更好的 cimport, syscall.

有任何想法吗?

谢谢。

标签: linuxcython

解决方案


您可以在 cython 的 github 存储库中查找这些包含的最佳方式,例如:stdio.h

应用它会导致:

%%cython
cdef extern from "<sys/syscall.h>" nogil:
    int __NR_gettid
    long syscall(long number, ...)

def gettid():
    return syscall(__NR_gettid)

现在gettid()产生:

>>> gettid()
7231

推荐阅读