Skip to content Skip to sidebar Skip to footer

Python Ctypes Calling Reboot() From Libc On Linux

I'm trying to call the reboot function from libc in Python via ctypes and I just can not get it to work. I've been referencing the man 2 reboot page (http://linux.die.net/man/2/re

Solution 1:

Try:

>>>libc = CDLL('libc.so.6', use_errno=True)

That should allow get_errno() to work.

[update]

Also, the last argument is a void *. If this is a 64-bit system, then the integer 0 is not a valid repesentation for NULL. I would try None or maybe c_void_p(None). (Not sure how that could matter in this context, though.)

[update 2]

Apparently reboot(0x1234567) does the trick (see comments).

Solution 2:

The reboot() in libc is a wrapper around the syscall, which only takes the cmd argument. So try:

libc.reboot(0x1234567)

Note that you should normally be initiating a reboot by sending SIGINT to PID 1 - telling the kernel to reboot will not give any system daemons the chance to shut down cleanly, and won't even sync the filesystem cache to disk.

Post a Comment for "Python Ctypes Calling Reboot() From Libc On Linux"