Shutdown (embedded) linux from kernel-space

别说谁变了你拦得住时间么 提交于 2019-11-30 20:06:22

The most general way would be for your driver to invoke shutdown as a userspace helper:

static const char * const shutdown_argv[] = 
    { "/sbin/shutdown", "-h", "-P", "now", NULL };

call_usermodehelper(shutdown_argv[0], shutdown_argv, NULL, UMH_NO_WAIT);

(Presuming you have a /sbin/shutdown binary installed). This will shut userspace down cleanly, unmount filesystems and then request the kernel shutdown and power off.

However, you may be able to do better than this - for example if you can guarantee that there's no disk filesystems mounted read/write, you could tell a kernel thread to invoke the kernel_power_off() function (it shouldn't be done from interrupt context).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!