I am not asking how to shut down. I am asking how to cut of the power.What is the function in Linux kernel code do the action of cutting of the power? And please explain the code.
Which function in Linux kernel do the powering off action?
kernel;drivers
The actual kernel code depends on the arch of your system. For x86 systems, they are located in arch/x86/kernel/reboot.cHalt will stop the machine, and leave it in power-on state. So it just stops the kernel, but usually does not power it off.static void native_machine_halt(void){  /* Stop other cpus and apics */  machine_shutdown();  tboot_shutdown(TB_SHUTDOWN_HALT);  stop_this_cpu(NULL);}While power_off will also cut off the electric source from APM / ACPI pm_power_off()static void native_machine_power_off(void){  if (pm_power_off) {    if (!reboot_force)      machine_shutdown();    pm_power_off();  }  /* A fallback in case there is no PM info available */  tboot_shutdown(TB_SHUTDOWN_HALT);}machine_shutdown() is an infinite looptboot_shutdown() (arch/x86/kernel/tboot.c)stop_this_cpu(NULL) (arch/x86/kernel/process.c)disables the IRQs of the CPU, set the CPU offline, pm_power_off() (arch/x86/kernel/apm_32.c) is a function pointer to apm_power_off()As you can see, all the job depends on the arch. In all cases, it's done with ASM calls.For apm_power_off(), the Bios is called with code APT_STATE_OFF (0x0003). apm_bios_call_simple(APM_FUNC_SET_STATE, APM_DEVICE_ALL, APM_STATE_OFF, eax, err);For native_halt() (arch/x86/include/asm/irqflags.h) this calls is used : asm volatile(hlt: : :memory);Choose your poison :)