[ Pobierz całość w formacie PDF ]
98
Chapter 11. Keeping Time
zone, make sure you ll upgrade at least that part of your Linux system. Other than setting the system
time zone and upgrading the time zone data files, there is little need to bother about time.
The hardware and software clocks
A personal computer has a battery driven hardware clock. The battery ensures that the clock will work
even if the rest of the computer is without electricity. The hardware clock can be set from the BIOS setup
screen or from whatever operating system is running.
The Linux kernel keeps track of time independently from the hardware clock. During the boot, Linux
sets its own clock to the same time as the hardware clock. After this, both clocks run independently.
Linux maintains its own clock because looking at the hardware is slow and complicated.
The kernel clock always shows universal time. This way, the kernel does not need to know about time
zones at all. The simplicity results in higher reliability and makes it easier to update the time zone
information. Each process handles time zone conversions itself (using standard tools that are part of the
time zone package).
The hardware clock can be in local time or in universal time. It is usually better to have it in universal
time, because then you don t need to change the hardware clock when daylight savings time begins or
ends (UTC does not have DST). Unfortunately, some PC operating systems, including MS-DOS,
Windows, and OS/2, assume the hardware clock shows local time. Linux can handle either, but if the
hardware clock shows local time, then it must be modified when daylight savings time begins or ends
(otherwise it wouldn t show local time).
Showing and setting time
In the Debian system, the system time zone is determined by the symbolic link/etc/localtime. This
link points at a time zone data file that describes the local time zone. The time zone data files are stored
in/usr/lib/zoneinfo. Other Linux distributions may do this differently.
A user can change his private time zone by setting the TZ environment variable. If it is unset, the system
time zone is assumed. The syntax of the TZ variable is described in thetzsetmanual page.
2
The date command shows 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
EET DST (which might be East European Daylight Savings Time). date can also show the univeral
99
Chapter 11. Keeping Time
time:
$ date -u
Sun Jul 14 18:53:42 UTC 1996
Sun Jul 14 18:53:42 UTC 1996
$
date is also used to set the kernel s software clock:
# date 07142157
Sun Jul 14 21:57:00 EET DST 1996
# date
Sun Jul 14 21:57:02 EET DST 1996
#
See the date manual page for more details; the syntax is a bit arcane. Only root can set the time. While
each user can have his own time zone, the clock is the same for everyone.
date only shows or sets the software clock. The clock commands syncronizes the hardware and software
clocks. It is used when the system boots, to read the hardware clock and set the software clock. If you
need to set both clocks, you first set the software clock with date, and then the hardware clock with
clock -w.
The -u option to clock tells it that the hardware clock is in universal time. You must use the -u option
correctly. If you don t, your computer will be quite confused about what the time is.
The clocks should be changed with care. Many parts of a Unix system require the clocks to work
correctly. For example, the cron daemon runs commands periodically. If you change the clock, it can be
confused of whether it needs to run the commands or not. 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. Current versions of cron can handle this correctly, but you should still be careful. Big jumps or
backward jumps are more dangeours than smaller or forward ones.
When the clock is wrong
The Linux software clock is not always accurate. It is kept running by a periodic timer interrupt
generated by PC hardware. If the system has too many processes running, it may take too long to service
the timer interrupt, and the software clock starts slipping behind. The hardware clock runs independently [ Pobierz całość w formacie PDF ]
zanotowane.pl doc.pisz.pl pdf.pisz.pl karpacz24.htw.pl
98
Chapter 11. Keeping Time
zone, make sure you ll upgrade at least that part of your Linux system. Other than setting the system
time zone and upgrading the time zone data files, there is little need to bother about time.
The hardware and software clocks
A personal computer has a battery driven hardware clock. The battery ensures that the clock will work
even if the rest of the computer is without electricity. The hardware clock can be set from the BIOS setup
screen or from whatever operating system is running.
The Linux kernel keeps track of time independently from the hardware clock. During the boot, Linux
sets its own clock to the same time as the hardware clock. After this, both clocks run independently.
Linux maintains its own clock because looking at the hardware is slow and complicated.
The kernel clock always shows universal time. This way, the kernel does not need to know about time
zones at all. The simplicity results in higher reliability and makes it easier to update the time zone
information. Each process handles time zone conversions itself (using standard tools that are part of the
time zone package).
The hardware clock can be in local time or in universal time. It is usually better to have it in universal
time, because then you don t need to change the hardware clock when daylight savings time begins or
ends (UTC does not have DST). Unfortunately, some PC operating systems, including MS-DOS,
Windows, and OS/2, assume the hardware clock shows local time. Linux can handle either, but if the
hardware clock shows local time, then it must be modified when daylight savings time begins or ends
(otherwise it wouldn t show local time).
Showing and setting time
In the Debian system, the system time zone is determined by the symbolic link/etc/localtime. This
link points at a time zone data file that describes the local time zone. The time zone data files are stored
in/usr/lib/zoneinfo. Other Linux distributions may do this differently.
A user can change his private time zone by setting the TZ environment variable. If it is unset, the system
time zone is assumed. The syntax of the TZ variable is described in thetzsetmanual page.
2
The date command shows 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
EET DST (which might be East European Daylight Savings Time). date can also show the univeral
99
Chapter 11. Keeping Time
time:
$ date -u
Sun Jul 14 18:53:42 UTC 1996
Sun Jul 14 18:53:42 UTC 1996
$
date is also used to set the kernel s software clock:
# date 07142157
Sun Jul 14 21:57:00 EET DST 1996
# date
Sun Jul 14 21:57:02 EET DST 1996
#
See the date manual page for more details; the syntax is a bit arcane. Only root can set the time. While
each user can have his own time zone, the clock is the same for everyone.
date only shows or sets the software clock. The clock commands syncronizes the hardware and software
clocks. It is used when the system boots, to read the hardware clock and set the software clock. If you
need to set both clocks, you first set the software clock with date, and then the hardware clock with
clock -w.
The -u option to clock tells it that the hardware clock is in universal time. You must use the -u option
correctly. If you don t, your computer will be quite confused about what the time is.
The clocks should be changed with care. Many parts of a Unix system require the clocks to work
correctly. For example, the cron daemon runs commands periodically. If you change the clock, it can be
confused of whether it needs to run the commands or not. 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. Current versions of cron can handle this correctly, but you should still be careful. Big jumps or
backward jumps are more dangeours than smaller or forward ones.
When the clock is wrong
The Linux software clock is not always accurate. It is kept running by a periodic timer interrupt
generated by PC hardware. If the system has too many processes running, it may take too long to service
the timer interrupt, and the software clock starts slipping behind. The hardware clock runs independently [ Pobierz całość w formacie PDF ]