我试图从Python的libc中通过调用reboot
函数,我只是无法让它工作。我一直在参考man 2 reboot
页(http://linux.die.net/man/2/reboot)。我的内核版本是2.6.35。python ctypes从Linux上的libc调用reboot()
下面是来自交互式Python提示符的控制台日志,我试图让我的机器重启 - 我做错了什么?
为什么不是ctypes.get_errno()
正常工作?
>>> from ctypes import CDLL, get_errno
>>> libc = CDLL('libc.so.6')
>>> libc.reboot(0xfee1dead, 537993216, 0x1234567, 0)
-1
>>> get_errno()
0
>>> libc.reboot(0xfee1dead, 537993216, 0x1234567)
-1
>>> get_errno()
0
>>> from ctypes import c_uint32
>>> libc.reboot(c_uint32(0xfee1dead), c_uint32(672274793), c_uint32(0x1234567), c_uint32(0))
-1
>>> get_errno()
0
>>> libc.reboot(c_uint32(0xfee1dead), c_uint32(672274793), c_uint32(0x1234567))
-1
>>> get_errno()
0
>>>
编辑:
通过Nemos reminder-我能得到get_errno
返回22(无效参数)。不出所料。我应该怎么叫reboot()
?我显然不会传递函数期望的参数。 =)
运行此脚本时,您是否是root用户? – 2011-06-01 02:25:52
访问被拒绝?我不知道...尝试(重新)阅读:http://linux.die.net/man/2/reboot – Manux 2011-06-01 02:26:32
即使访问被拒绝,人们会期望'errno'报告'EPERM'。 – sarnold 2011-06-01 02:27:47