<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>leap time | 酷 壳 - CoolShell</title>
	<atom:link href="https://coolshell.cn/tag/leap-time/feed" rel="self" type="application/rss+xml" />
	<link>https://coolshell.cn</link>
	<description>享受编程和技术所带来的快乐 - Coding Your Ambition</description>
	<lastBuildDate>Tue, 03 Jul 2012 01:40:58 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2</generator>
	<item>
		<title>关于闰秒</title>
		<link>https://coolshell.cn/articles/7804.html</link>
					<comments>https://coolshell.cn/articles/7804.html#comments</comments>
		
		<dc:creator><![CDATA[陈皓]]></dc:creator>
		<pubDate>Sat, 30 Jun 2012 09:16:34 +0000</pubDate>
				<category><![CDATA[杂项资源]]></category>
		<category><![CDATA[leap time]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[timestamp]]></category>
		<guid isPermaLink="false">http://coolshell.cn/?p=7804</guid>

					<description><![CDATA[<p>2012年6月30日，也就今天晚上，时间会多出现一秒，也就是我们所说的闰秒。我不知道大家对闰秒的了解有多少，所以写下这篇文章。 背景知识 闰秒是在在UTC（中文...</p>
<p class="read-more"><a class="btn btn-default" href="https://coolshell.cn/articles/7804.html"> Read More<span class="screen-reader-text">  Read More</span></a></p>
The post <a href="https://coolshell.cn/articles/7804.html">关于闰秒</a> first appeared on <a href="https://coolshell.cn">酷 壳 - CoolShell</a>.]]></description>
										<content:encoded><![CDATA[<p><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3415450859608158"
     crossorigin="anonymous"></script>2012年6月30日，也就今天晚上，时间会多出现一秒，也就是我们所说的闰秒。我不知道大家对闰秒的了解有多少，所以写下这篇文章。</p>
<h4>背景知识</h4>
<p>闰秒是在在<a href="http://en.wikipedia.org/wiki/Coordinated_Universal_Time" target="_blank">UTC</a>（中文“世界标准时间”或“世界协调时间<strong>”</strong>／英文“<strong>C</strong>oordinated <strong>U</strong>niversal <strong>T</strong>ime”／法文“<strong>T</strong>emps <strong>U</strong>niversel <strong>C</strong>ordonné”）是基于<a href="http://en.wikipedia.org/wiki/Atomic_clock" target="_blank">Atomic Clock</a>（原子时钟）的一种时间，向太阳时（<a title="Mean solar day" href="http://en.wikipedia.org/wiki/Mean_solar_day">Solar Time </a>）对齐的一种方法，因为太阳时是根据地球公转来计算的。所以，1972年制定的UTC为了确保其时间相对于UTC的时间误差不能超过0.9秒，因此在过一段时间后需要加一秒。下图是有UTC以来闰秒的调整表（来自<a href="http://zh.wikipedia.org/wiki/%E9%97%B0%E7%A7%92" target="_blank">Wikipedia闰秒的中文词条</a>）</p>
<p><img decoding="async" loading="lazy" class="aligncenter size-full wp-image-7805" title="闰秒" src="https://coolshell.cn/wp-content/uploads/2012/06/闰秒.png" alt="" width="433" height="383" srcset="https://coolshell.cn/wp-content/uploads/2012/06/闰秒.png 433w, https://coolshell.cn/wp-content/uploads/2012/06/闰秒-300x265.png 300w, https://coolshell.cn/wp-content/uploads/2012/06/闰秒-305x270.png 305w" sizes="(max-width: 433px) 100vw, 433px" /></p>
<p><span id="more-7804"></span></p>
<p>从上表中我们可以看到，从1972年到现在，在这四十年里已经进行过25次的闰秒调整。闰秒是在每年6月或12月的最后一天的最后一分钟进行跳秒或不跳秒。是否加入闰秒由位于巴黎的国际地球自转和参考坐标系统服务（IERS &#8211; <a title="International Earth Rotation and Reference Systems Service" href="http://en.wikipedia.org/wiki/International_Earth_Rotation_and_Reference_Systems_Service">International Earth Rotation and Reference Systems Service</a>）决定。如果决定加入闰秒，那么这一秒是被加在第二天的00:00:00前的，也就是说，时间会出现23:59:60的情况，然后才是第二天的00:00:00。如果是负闰秒的话，23:59:58的下一秒就直接跳到第二天的00:00:00了。<strong>现在，所有闰秒都是正闰秒</strong>。</p>
<h4>计算机处理闰秒</h4>
<p>那么，对于我们的电脑系统来说，怎么处理这个闰秒呢？一般来说，我们需要为我们的电脑系统配置UTC时钟，并通过NTP (<a title="Network time protocol" href="http://en.wikipedia.org/wiki/Network_time_protocol">Network time protocol</a>)来进行时间同步，NTP服务器会一级一级地下发闰秒事件通知直到最边缘的NTP服务器，然后NTP服务器就会把闰秒通知发给客户端的操作系统，由操作系统来处理闰秒通知。</p>
<p>虽然闰秒调整对普通民众的日常生活不会产生影响。不过，<strong>这个问题将影响部分开启ntp服务的Linux操作系统——会导致Linux内核Crash！</strong>Linux kernel是在2.6.18-164.e15之后的版本中解决了这个问题。<span style="color: #cc0000;">换句话说，Linux kernel低于<strong>2.6.18-164</strong>的Linux系统，无论是什么公司的Linux都将受到影响</span>。（今晚过后大家可以查看一下你的Linux系统日志，看看闰秒有没有发生）</p>
<p>可以参看下面的bug描述：</p>
<ul>
<li><a href="https://lkml.org/lkml/2009/1/2/373" target="_blank">LKML: Chris Adams: Re: Bug: Status/Summary of slashdot leap-second crash on new years 2008-2009</a></li>
<li><a href="https://bugzilla.redhat.com/show_bug.cgi?id=479765" target="_blank">Bug 479765 &#8211; Leap second message can hang the kernel</a></li>
</ul>
<p>那么，我们的操作系统是怎么处理正闰秒通知的？通常来说有三种实现：</p>
<ol>
<li>后退一秒。</li>
<li>停止一秒。</li>
<li>真正的增加一秒。</li>
</ol>
<p>懂编程的人一眼就能看出来，前两种方式是以一种Workaround或Hack的方式解决这个问题。第一种方式会导致一些基于timestamp的消息通知乱序了，而第二种会导致出现两个一模一样的timestamp。最后一种不会出现timestamp的问题。对了，你还记得以前那篇《<a href="https://coolshell.cn/articles/5075.html" rel="bookmark">你确信你了解时间吗？</a>》的文章吗？</p>
<p>最后，说说Windows，Windows  Time Service不支持闰秒通知，所以，当闰秒发生的时候，你的Windows上的时间会比实际时间快一秒钟，这需要等下一次的时钟同步才会完成修正。你可以查看这篇文章：<a href="http://support.microsoft.com/kb/909614/en-us">http://support.microsoft.com/kb/909614/en-us</a></p>
<p>（全文完）<!--



<p align="center"><a href= target=_blank><img decoding="async" src=""></a></p>





<p align="center"><img decoding="async" src="https://coolshell.cn/wp-content/uploads/2020/03/coolshell.weixin.jpg"> <img decoding="async" loading="lazy" src="https://coolshell.cn/wp-content/uploads/2020/03/coolshell.mini_.jpg" width="300" height="300"> <br />关注CoolShell微信公众账号和微信小程序</p>

 

--></p>
<div style="margin-top: 15px; font-size: 16px;color: #cc0000;">
<p align="center"><strong>（转载本站文章请注明作者和出处 <a href="https://coolshell.cn/">酷 壳 &#8211; CoolShell</a> ，请勿用于任何商业用途）</strong></p>
</div>

<div class="wp_rp_wrap  wp_rp_vertical_m" id="wp_rp_first"><div class="wp_rp_content"><h3 class="related_post_title">相关文章</h3><ul class="related_post wp_rp"><li ><a href="https://coolshell.cn/articles/22320.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2022/12/eBPF-150x150.jpeg" alt="eBPF 介绍" width="150" height="150" /></a><a href="https://coolshell.cn/articles/22320.html" class="wp_rp_title">eBPF 介绍</a></li><li ><a href="https://coolshell.cn/articles/19219.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2019/03/linux.ninja_-150x150.png" alt="打造高效的工作环境 &#8211; Shell 篇" width="150" height="150" /></a><a href="https://coolshell.cn/articles/19219.html" class="wp_rp_title">打造高效的工作环境 &#8211; Shell 篇</a></li><li ><a href="https://coolshell.cn/articles/18654.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2018/12/docker-networking-1-150x150.png" alt="记一次Kubernetes/Docker网络排障" width="150" height="150" /></a><a href="https://coolshell.cn/articles/18654.html" class="wp_rp_title">记一次Kubernetes/Docker网络排障</a></li><li ><a href="https://coolshell.cn/articles/18360.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2018/05/300x262-150x150.jpg" alt="程序员练级攻略（2018)  与我的专栏" width="150" height="150" /></a><a href="https://coolshell.cn/articles/18360.html" class="wp_rp_title">程序员练级攻略（2018)  与我的专栏</a></li><li ><a href="https://coolshell.cn/articles/17998.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2017/07/systemd-1-150x150.jpeg" alt="Linux PID 1 和 Systemd" width="150" height="150" /></a><a href="https://coolshell.cn/articles/17998.html" class="wp_rp_title">Linux PID 1 和 Systemd</a></li><li ><a href="https://coolshell.cn/articles/17416.html" class="wp_rp_thumbnail"><img src="https://coolshell.cn/wp-content/uploads/2016/07/cache-150x150.png" alt="缓存更新的套路" width="150" height="150" /></a><a href="https://coolshell.cn/articles/17416.html" class="wp_rp_title">缓存更新的套路</a></li></ul></div></div>The post <a href="https://coolshell.cn/articles/7804.html">关于闰秒</a> first appeared on <a href="https://coolshell.cn">酷 壳 - CoolShell</a>.]]></content:encoded>
					
					<wfw:commentRss>https://coolshell.cn/articles/7804.html/feed</wfw:commentRss>
			<slash:comments>35</slash:comments>
		
		
			</item>
	</channel>
</rss>
