python读取某一符号_获取已触发某些符号的进程的pid

POSIX Linux

在C语言中,我设法让它运行起来很容易:

在#include

#include

#include

#include

static void my_handler(int signum, siginfo_t *siginfo, void *context) {

printf("Got signal '%d' from process '%d' of user '%d'\n",

signum, siginfo->si_pid, siginfo->si_uid);

}

int main(void) {

struct sigaction act;

memset(&act, '\0', sizeof(act));

act.sa_sigaction = &my_handler;

act.sa_flags = SA_SIGINFO;

sigaction(SIGUSR1, &act, NULL);

printf("Hi, my pid is %d\ntalk to me with 'kill -SIGUSR1 %d'\n", getpid(), getpid());

while(1)

sleep(1000);

return 0;

}

我的3.1.6香草内核和gcc4.4.5运行得很好——但在python中找不到任何对它的支持。在

也许我以前就尝试过用Python来构建我的交互,但我以前从未尝试过

sigpidmodule.c

^{pr2}$

在设置.py对于构建模块:

在from distutils.core import setup, Extension

module1 = Extension('sigpid', sources= ['sigpidmodule.c'])

setup (name='SigPid', version='1.0',

description='SigPidingStuff',

ext_modules = [module1])

使用构建模块python setup.py build

因此,仍然缺少使用模块的python脚本:测试.py

在import sigpid

import time, os

def callme(num, pid):

'''

Callback function to be called from c module

'''

print "py: got %d from %d\n" % (num, pid)

# register the callback:

sigpid.register(callme)

print "py: Hi, I'm %d, talk to me with 'kill -SIGUSR1 %d'" %(os.getpid(),os.getpid())

# wait for signal while doing nothing:

while True:

time.sleep(1)

一切都很好。。。最多:python test.py

或者我不得不这样称呼它来纠正自由党:PYTHONPATH=build/lib.linux-i686-2.6 python test.py

输出:

在c: callback now: 0xb744f534

py: Hi, I'm 2255, talk to me with 'kill -SIGUSR1 2255'

(from other term: kill -SIGUSR1 2255)

c: Signal reached c handler: signum=10, pid=2948, handler=0xb744f534

c: calling python callback

Segmentation fault

我不知道我为什么会遇到这个错误,我已经没有办法解决它了。我想这一定与c和python的交互方式有关(我可以想到一些原因,但这只是猜测)。也许在c-python-interaction方面有更多经验的人可以在这里提供帮助(或者至少解释一下,到底是什么问题)。我们也许有办法解决这个问题,至少在linux上是这样。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值