我試圖從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