Stopping a UNIX machine

There are many ways to do this:

shutdown -h now 

Shuts down now, halts and returns to the machine’s console prompt.

shutdown -r now 

Shuts down now and reboots.

reboot 

Same as the above.

You can also use shutdown to specify a time for shutdown, but this is of limited use.
 

Flushing the cache

If you ever have to turn off a system running UNIX, it is essential to flush the cache.  UNIX uses write-behind caching: you might think you wrote a file to disk, but chances are it’s still in RAM.  Therefore, switching off the power makes a mess of UNIX.

Type sync. Wait.

When the prompt returns, assuming no other processes (i.e. users) write to disk, you can switch off in relative safety.
 

Broadcasting messages to people

If you want to shut down and there are people on the system, it is courteous to tell them.

wall 

Short for “write all”. You need to be root (superuser). Type in your message, press ^D to finish (or ^C to abort).

write user 

The same, but to a particular user.

cat > /dev/ttyxx 

The rude and amusing way to do it. If you know what terminal they’re logged on at (see Managing Processes and Snooping below), and you are superuser, you can write directly to their terminal. That way you don’t get the beep and the message saying “Message from …”. It can really confuse people :-)
 

Which machine am I on?

Type hostname. If it’s not what you expect, don’t shut it down!
 

In summary, after testing out of curiosity than for any practical purpose, these are the methods we found, listed in order from slow and safe to fast and dangerous for stopping a UNIX machine.

1) shutdown -h now

2) shutdown -fh now

Some systems use "-F" instead of "-f". Is supposed to skip some safety measures and therefore to be faster.

3) sync ; sync ; halt

Will be even faster but might (only in extreme cases) damage the system because it stops without anything being closed in order. Still, most systems will survive this and boot more or less properly after being killed that way.

4) halt -q

Even faster, but don't try this without a journaling file system (don't try this at all without the need to do so). Old SunOS versions, for instance, had a fair chance of not coming up properly again after such a nosedive. Even with a journaling FS there is some risk, which is why it should only be used as either a very extreme measure or for testing purposes on expendable (test) systems. The same goes for the "winner":

5) cat /etc/hosts > /dev/kmem

Any other file will do too - i use this just out of habit. On POWER and PC hardware (and probably on most other hardware too) this was consistently faster than even "halt -q", it takes only about a dozen bytes to be written over the kernel image to crash the system. In AIX this is not possible any more, because even root cannot write to /dev/kmem in newer versions. 

Unix Tips

See Also
Unix Command To Find All Users

Have a Unix Problem
Unix Forum - Do you have a UNIX Question?

Unix Books :-
UNIX Programming, Certification, System Administration, Performance Tuning Reference Books

Return to : - Unix System Administration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.
The site www.gotothings.com is in no way affiliated with or endorsed by any company listed at this site.
Any unauthorised copying or mirroring is prohibited.