Linux关机命令详解

Stupig posted @ 2010年7月13日 06:36 in Linux with tags linux shutdown 关机 , 2183 阅读

  在Linux下一些常用的关机/重启命令有shutdown、halt、reboot、及init,它们都可以达到重启系统的目的,但每个命令的内部工作过程是不同的,通过本文的介绍,希望你可以更加灵活的运用各种关机命令。

  1、shutdown

  shutdown命令安全地将系统关机。有些用户会使用直接断掉电源的方式来关闭Linux,这是十分危险的。因为Linux与Windows不同,其后台运行着许多进程,所以强制关机可能会导致进程的数据丢失,使系统处于不稳定的状态,甚至在有的系统中会损坏硬件设备。

  而在系统关机前使用shutdown命令,系统管理员会通知所有登录的用户系统将要关闭。并且login指令会被冻结,即新的用户不能再登录。直接关机或者延迟一定的时间才关机都是可能的,还可能重启。这是由所有进程(process)都会收到系统所送达的信号(signal)决定的。这让像vi之类的程序有时间储存目前正在编辑的文档,而像处理邮件(mail)和新闻(news)的程序则可以正常地离开等等。

  shutdown执行它的工作是送信号(signal)给init程序,要求它改变runlevel。

  runlevel 0被用来停机(halt),runlevel 6是用来重新激活(reboot)系统,而runlevel 1则是被用来让系统进入管理工作可以进行的状态﹔这是预设的,假定没有-h也没有-r参数给shutdown。要想了解在停机(halt)或者重新开机(reboot)过程中做了哪些动作,你可以在这个文件/etc/inittab里看到这些runlevels相关的资料。

  shutdown 参数说明:

  [-t] 在改变到其它runlevel之前,告诉init多久以后关机。

  [-r] 重启计算器。

  [-k] 并不真正关机,只是送警告信号给每位登录者(login)。

  [-h] 关机后关闭电源(halt)。

  [-n] 不用init,而是自己来关机。不鼓励使用这个选项,而且该选项所产生的后果往往不总是你所预期得到的。

  [-c] cancel current process取消目前正在执行的关机程序。所以这个选项当然没有时间参数,但是可以输入一个用来解释的讯息,而这信息将会送到每位使用者。

  [-f] 在重启计算器(reboot)时忽略fsck。

  [-F] 在重启计算器(reboot)时强迫fsck。

  [-time] 设定关机(shutdown)前的时间。

  2、halt——最简单的关机命令

  其实halt就是调用shutdown -h。halt执行时,杀死应用进程,执行sync系统调用,文件系统写操作完成后就会停止内核。

  参数说明:

  [-n] 防止sync系统调用,它用在用fsck修补根分区之后,以阻止内核用老版本的超级块(superblock)覆盖修补过的超级块。

  [-w] 并不是真正的重启或关机,只是写wtmp(/var/log/wtmp)纪录。

  [-d] 不写wtmp纪录(已包含在选项[-n]中)。

  [-f] 没有调用shutdown而强制关机或重启。

  [-i] 关机(或重启)前,关掉所有的网络接口。

  [-p] 该选项为缺省选项。就是关机时调用poweroff。

  3、reboot

  reboot的工作过程差不多跟halt一样,不过它是引发主机重启,而halt是关机。它的参数与halt相差不多。

  4、init

  init是所有进程的祖先,它的进程号始终为1,所以发送TERM信号给init会终止所有的用户进程﹑守护进程等。shutdown 就是使用这种机制。init定义了8个运行级别(runlevel),init 0为关机,init 1为重启。关于init可以长篇大论,这里就不再叙述。另外还有telinit命令可以改变init的运行级别,比如,telinit -iS可使系统进入单用户模式,并且得不到使用shutdown时的信息和等待时间。

AAA 说:
2021年8月09日 21:16

Wow! Such an amazing and helpful post this is. I really really love it. It's so good and so awesome. I am just amazed. I hope that you continue to do your work like this in the future also Pharmacy Technician certification training online course

BASIT 说:
2021年8月15日 15:21

I can see that you are an expert at your field! I am launching a website soon, and your information will be very useful for me.. Thanks for all your help and wishing you all the success in your business. buy pva gmail account

dfg` 说:
2021年8月22日 17:54

Sometimes it is what's more a reasonably fine text that him and i unquestionably liked investigating. Not always every day which will have fun with the probability to see a supplement. กีฬา

dfg` 说:
2021年8月25日 21:09

You understand your projects stand out of the crowd. There is something unique about them. It seems to me all of them are brilliant. buy youtube subscribers

dfg` 说:
2021年8月26日 22:46

Therefore dissertation web-sites as a result of online to set-up safe and sound ostensibly taped in the website. slot machine tricks cheats

dfg` 说:
2021年9月11日 17:01

You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. krt carts

dfg` 说:
2021年9月12日 14:26

Your article has piqued a lot of positive interest. I can see why since you have done such a good job of making it interesting. 美国代写被抓

dfg` 说:
2021年9月13日 15:55

This particular looks for example certainly superb. Most of these slight tips are made using availablility of cosmetic foundation interest. I like to him or her appreciably. 먹튀사이트

dfg` 说:
2021年9月14日 14:30

I haven’t any word to appreciate this post.....Really i am impressed from this post....the person who create this post it was a great human..thanks for shared this with us. jackpot party casino coins

dfg` 说:
2021年10月08日 00:07

I’ve been surfing online more than three hours today, yet I never found any interesting article like yours. It’s pretty worth enough for me. In my opinion, if all webmasters and bloggers made good content as you did, the web will be a lot more useful than ever before. white label real estate crowdfunding software

dfg` 说:
2021年10月12日 22:16

When you use a genuine service, you will be able to provide instructions, share materials and choose the formatting style. VPN검증

dfg` 说:
2021年10月28日 23:16

it's really nice and meanful. it's really cool blog. Linking is very useful thing.you have really helped lots of people who visit blog and provide them usefull information. sildalis 120

satac key dates 说:
2021年11月03日 20:03

مانا رشــفة متجــر وتطبيــق الكترونــي مختــص فــي بيــع وتوصيــل ميــاه الشــرب الــى المنــازل او المســاجد او أي مــكان تحددونــه مــن خــال وســائل النقــل التــي نمتلكهــا بالإضافــة الــى مســتودعاتنا المنتشــرة فــي عمــوم المملكــة لضمــان الســرعة والكفــاءة بالعمــل كل ذلــك عــن طريـق تطبيـق بتصميم بسـيط سـهل الإ

satac key dates 说:
2021年11月03日 22:00

best website design & development agency Charlotte NC We're not just another website company. Evolution in technology is continually transforming how businesses operate and how people interact with the world.

satac key dates 说:
2021年11月04日 16:17

soap2day.eus Soap2day is a FREE Movie Streaming site to watch movies and tv series. Soap2dayto, soap2day to, soap 2 day, soaptoday is free and safe to use.

satac key dates 说:
2021年11月04日 21:37

Get Third-party risk management software in UK LEVIZO provide Third-party risk management services in UK, Information security services in UK and Information risk management Services in UK. Contact us today for more details and quotation.

AAA 说:
2022年2月10日 21:09

If you set out to make me think today; mission accomplished! I really like your writing style and how you express your ideas. Thank you. StartEngine Fees

AAA 说:
2022年2月10日 21:09

This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. Republic Stocks

AAA 说:
2022年2月10日 21:10

This was a really great contest and hopefully I can attend the next one. It was alot of fun and I really enjoyed myself.. StartEngine Success Stories

AAA 说:
2022年2月11日 03:05

I am unable to read articles online very often, but I’m glad I did today. This is very well written and your points are well-expressed. Please, don’t ever stop writing. ยี่กี่ lotto

AAA 说:
2022年2月11日 03:05

Yes, I am entirely agreed with this article, and I just want say that this article is very helpful and enlightening. I also have some precious piece of concerned info !!!!!!Thanks. xoslot

AAA 说:
2022年2月18日 22:57

Nice post. I learn something tougher on distinct blogs everyday. Most commonly it is stimulating to see content off their writers and use a little there. I’d want to use some with all the content on my blog whether you don’t mind. Natually I’ll offer you a link on the web weblog. Many thanks sharing. محامي السعودية

 

 

=====================================

 

 

I enjoy your work , regards for all the informative posts . شراء عقارات تركيا

 

 

==============================================

 

I very delighted to find this web site on bing, just what I was looking for besides saved to bookmarks . محامي السعودية

AAA 说:
2022年3月03日 15:08

I am happy to find this post Very useful for me, as it contains lot of information. I Always prefer to read The Quality and glad I found this thing in you post. Thanks florarie florisis

AAA 说:
2022年3月10日 17:21

The writer has outdone himself this time. It is not at all enough; the website is also utmost perfect. I will never forget to visit your site again and again. Book appointment

AAA 说:
2022年3月19日 01:35

Very informative post! There is a lot of information here that can help any business get started with a successful social networking campaign. Book now

AAA 说:
2022年3月22日 16:07

Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me. Liv@MB Floor Plan

 

 

=================================================

 

 

Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place.. inpoterbaru

AAA 说:
2022年3月31日 21:11 i am always looking for some free stuffs over the internet. there are also some companies which gives free samples. Beard recovery
AAA 说:
2022年4月12日 04:00

Your article has piqued a lot of positive interest. I can see why since you have done such a good job of making it interesting. jili slot

AAA 说:
2022年4月12日 04:45

An interesting dialogue is price comment. I feel that it is best to write more on this matter, it may not be a taboo topic however usually individuals are not enough to talk on such topics. To the next. Cheers. pragmatic play

AAA 说:
2022年4月12日 18:43

The article looks magnificent, but it would be beneficial if you can share more about the suchlike subjects in the future. Keep posting. 918kiss

AAA 说:
2022年4月12日 19:46

The article looks magnificent, but it would be beneficial if you can share more about the suchlike subjects in the future. Keep posting. sa game

AAA 说:
2022年4月18日 19:37

<p>
You make so many great points here that I read your article a couple of times. Your views are relating with my own for the most part. That is great content for the readers. <a href="http://horizonvirtual360.com">Virtual tours yorkshire</a></p>

ronymakalulu 说:
2022年9月27日 13:55

Apa itu backlink? Singkat saja, backlink adalah tautan yang mengarah ke blog kita dari situs web lain, misalnya anda berkomentar di blog orang lain dan meninggalkan link atau alamat url blog anda. [url=https://ubiseo.com]jasa seo[/url]


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter