Linux administrator Manual (9)

Source: Internet
Author: User

This chapter describes how to keeps time in Linux and how to avoid problems. Generally, you do not need to do anything about time, but it is better to understand it.

Time Zone

Time measurement is based on the most regular natural phenomenon, such as the day and night change caused by rotation of the earth. The total time between day and night is constant, but the length of the day and night is changing. A simple constant is midday.

Midday is the time when the sun is at its highest point during the day. Because the earth is round, midday occurs at different times in different places. This introduces the concept of local time.

Hardware clock and Software Clock

A pc has a battery-driven hardware clock. The battery always works when the computer is not powered. The hardware can always be set from the BIOS settings screen or somewhere else in the operating system.

The Linux core is independent of the hardware tracking time. At startup, Linux sets its own clock based on the hardware clock. Since then, the two have always run independently of each other. Because viewing hardware is always slow and complex, Linux manages its own clock.

The general time of the core is always displayed. In this way, the core does not need to know the time zone. Highly Reliable and simple results make it easier to update the time zone information. Each process processes the time zone conversion by itself (using the standard tool in the time zone package ).

The hardware can always be local time or general time. Generally, the general time is better, because you do not need to change the hardware clock (UTC does not have DST) at the start or end of the daylight saving time ). Unfortunately, some PC operating systems, including MSDOS, Windows, and OS/2, assume that the hardware clock is local time. Linux supports two methods. However, if the hardware clock displays the local time, the local time must be displayed at the start or end of the Daylight Saving Time (otherwise, the local time cannot be displayed ).

Display and set the clock

In the Debian system, the system time zone is determined by the symbolic connection/etc/localtime. Connects to the time zone data file that describes the local time zone. The time zone data file exists in/usr/lib/zoneinfo. Other Linux distributions may be different.

Users can change their private time zone by setting TZ environment variables. If this parameter is not set, the system time zone is used. The TZ variable syntax is described on the tzset (3) man page.

The date command displays the current date and time. For example:

$ Date
Sun Jul 14 21:53:41 eet dst 1996
$
That time is Sunday, 14th of July, 1996, at about ten before ten at the evening, in the time zone called ''et DST ''(which might be East European Daylight Savings Time ). date can also be used to display the common time:
$ Date-u
Sun Jul 14 18:53:42, UTC 1996
$
Date can also be used to set the core software to always:
# Date 07142157
Sun Jul 14 21:57:00 eet dst 1996
# Date
Sun Jul 14 21:57:02 eet dst 1996
#

For more details, see date man -- syntax is a bit arcane. Only root can set the time. Although each user can have their own time zone, the clock is the same for everyone.

Date only displays or sets the Software Clock. The clock command synchronizes the hardware and software clock. It is used to read the hardware clock and set the software clock when the system starts. If both clocks need to be set, set the Software clock with date, and then set the hardware clock with clock-w.

Clock's-u tells it that the hardware clock is a common time. You must use the-u option correctly. Otherwise, the computer will be confused about the time.

The clock must be changed with caution. Many parts of Unix systems require that the clock work properly. For example, the cron daemon program runs commands cyclically. If you change the clock, it may confuse whether to run the command. On one early Unix system, someone set the clock twenty years into the future, and cron wanted to run all the periodic commands for twenty years all at once. the current version of cron can be handled correctly, but be careful. Large front and back jumps are more dangerous than small ones.

When the clock is incorrect

Linux software clock is not always accurate. The Software Clock is run periodically when the PC hardware is interrupted. If the system runs too many processes, it takes too much time to interrupt the service time, and the software clock starts from the back. The hardware clock runs independently and is usually more accurate. If your system is often started (for example, not most of the servers), the time is usually accurate.

If you need to adjust the hardware clock, the simplest thing is to restart, enter the BIOS settings screen, and complete it there. This avoids all problems that may result from changing the system time. If you cannot use BIOS, use date and clock to set a new time (in this Order), but if some of the system is not working properly, you must prepare to restart.

Connected computers (even through modem) can automatically check their clock by comparing their time with other computers. If you know other computers that keep accurate time, both computers will keep accurate time. This can be done using the rdate and netdate commands. Both commands check the remote computer (netdate can process multiple remote computers) To synchronize the Time of the local computer. Running such a program regularly keeps your computer as accurate as a remote computer.

Measuring Holes)

This appendix contains an interesting part of the procedure for measuring potential holes in a file system. The source distribution of the book contains the full source code (outputs/measure-holes/measure-holes.c ).

Int process (FILE * f, char * filename ){
Static char * buf = NULL;
Static long prev_block_size =-1;
Long zeroes;
Char * p;

If (buf = NULL | prev_block_size! = Block_size ){
Free (buf );
Buf = xmalloc (block_size + 1 );
Buf [block_size] = 1;
Prev_block_size = block_size;
}
Zeroes = 0;
While (fread (buf, block_size, 1, f) = 1 ){
For (p = buf; * p = '\ 0 ';)
++ P;
If (p = buf + block_size)
Zeroes + = block_size;
}
If (zeroes> 0)
Printf ("% ld % s \ n", zeroes, filename );
If (ferror (f )){
Errormsg (0,-1, "read failed for '% S'", filename );
Return-1;
}
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.