You are here:

C/Shut down !

Advertisement


Question
how to write system shut down program with c?

Answer
Hi Dear Sandeep Kumar !
  Before programming shut down thats good to know what is SHUT DOWN ?

Its nothing but a safe point where the operating system release the allocated resources and flush out the buffer that has been used so far !

More Over SHUTDOWN shut downs the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped. ( you might have experienced if you have used WIN 98 , it will show you a familiar message " ITS NOW SAFE TO TURN OFF YOUR COMPUTER " , then you have to manually power off the computer ! ( Power off operation is completely a hardware dependent operation )
 Let me summarize you the terms related with shut down operation !  
 POWEROFF: Exits Windows, then turns off the computer’s power (provided the computer supports the power-off feature).
  REBOOT: Shuts down the system, then restarts it. (Same as Start Menu | Shutdown | Restart.)
 LOGOFF: Shuts down all running processes, logs the user off, then restarts the Windows shell. (Same as Logoff on
the Start Menu.)

So as i said earlier shut down process is depend on the operating system , where as the power off operation is the sole responsibility of the Hardware , make sure both are not same !

So how the shut down operation works ?

  One of the tasks the power button performs is powering down a computer. However, computers are complex devices and can not be turned on and off like a light bulb without the possibility of damaging the computer. Computers run various processes and operations that can lose data or damage system files if they are abruptly terminated. Consequently, powering down a computer is a more complicated process than simply turning off a light bulb or other switch. For example, a cache temporarily stores data before it is written to a drive or system memory. Data cached in volatile memory is lost when the computer is powered off. If a cache is powered down prematurely, critical data may be lost.

Computers may contain power management controllers that allow the user to safely power down a computer. Power management controllers react to power button input by generating a system interrupt. The system interrupt may trigger an operating system (OS) based power management controller or a basic input/output system (BIOS) power management controller to handle the power button push event. The system software (BIOS or OS based power management handler) can then handle the power button push event according to its overall power management policies. Some system software could initiate a controlled system shut down or a transition to a sleep state. This software may power down the computer or it may force the computer system to progress to a shut down state in which the power can be turned off without damaging the computer or losing data.

 Here ill present you a simple C Program to restart the computer using BIOS interrupt 0x19

#include<bios.h>
void main()
{
 geninterrupt(0x19);
}

This simple program will restart your computer system ( Make sure that this interrupt will work fine only in DOS environment ( Ie your system should contain only DOS os )

Note : The above program is compiled and tested in Turbo C/C   compiler !

If you need any more detailed discussion over this topic feel free to ask a follow up , since this question is Purely a hardware related and so i just skipped some topics due to complexity , sure its hared to understand !


Thanks and Regards !
Prince M. Premnath

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.