如何安全强制关闭Mac [英] How to Safely Force Shutdown of Mac

查看:318
本文介绍了如何安全强制关闭Mac的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要的



我正在开发一个小应用程式,强迫我只在一天的某些时间工作 - 强迫我在晚上停止工作,所以我可以在一天中更有效。



OS X中的选项在某个时间关闭我的机器太容易取消。



我希望我的应用程序退出所有应用程序,无论他们是否有未保存的工作。


$ b

我尝试过的

但我已经读过,这可能会导致数据损坏。



我遇到了shutdown命令 - 我使用sudo shutdown -h +0立即关闭。这似乎只是票,但我担心,如果,如果磁盘实用程序正在做某种扫描可能会导致数据损坏。





shutdown命令是否会导致损坏?还是使用安全吗?有没有更好的方法强制关闭安全?

解决方案

shutdown命令向运行进程发送一个信号终止,做清理工作,如果需要。因此,一般来说,当应用程序接收到此信号( SIGTERM (inate))时,应该结束并退出。



IIRC在Snow Leopard(10.6)苹果添加了一个名为fast-shutdown(或类似)的东西,它会发送一个标记为正确的进程,用 SIGKILL 信号关闭它们下来没有机会进行清理工作。这应该使关闭更快。默认是应用程序仍然获得 SIGTERM ,并且必须选择加入 SIGKILL ;他们可以将自己标记为脏,即。 e。具有未保存的工作,不想被强行杀死。



因此,当在磁盘实用程序中间关闭时,将中止任何磁盘实用程序正在做,IMHO不会导致数据损坏一般。但是,根据当前正在运行的操作,可能会出现一个不完整的磁盘映像或半格式化的分区。



使用 cron c>调度关机是一个可行的选项,如果你想它发生在指定的时间。如果您希望在登录后的一定时间后发生,您可以使用number参数关闭以指定从现在开始的8小时。


What I want

I'm developing a little app to force me to only work at certain times of day - I need something to force me to stop working in the evenings so I can be more effective in the day.

The option within OS X to shut down my machine at a certain time is too easy to cancel. And you can always log back in afterwards.

I want my app to quit all applications whether they have unsaved work or not.

What I've tried

I thought of killing the loginwindow process, but I've read that this can cause data corruption.

I've come across the shutdown command - I'm using sudo shutdown -h +0 to shutdown immediately. This appears to be just the ticket, but I'm worried that it might cause data corruption if, say, Disk Utility is doing some kind of scan.

Is the shutdown command safe?

Can the shutdown command cause corruption? Or is it safe to use? Is there a better way of forcing shutdown safely?

解决方案

The shutdown command sends running processes a signal to terminate, giving them a chance to do clean up work, if needed. So generally, when an application receives this signal (SIGTERM(inate)) it should wrap up and exit.

IIRC in Snow Leopard (10.6) Apple added something called fast-shutdown (or similar) which will send processes that have been flagged as being ok with it a SIGKILL signal, shutting them down without chance for cleanup work. This is supposed to make shutdown faster. The default is that applications still get SIGTERM and have to opt-in for SIGKILL; and they can mark themselves as "dirty", i. e. having unsaved work and do not want to be killed forcibly.

So while shutting down in the middle of a disk utility run will abort whatever disk utility is doing, IMHO it would not cause data corruption in general. However depending on the operation you are currently running, you could end up with an incomplete disk image or a half-formatted partition. Maybe you want to refrain from using it when you know the end of your configured work time is coming close.

Using cron to schedule the shutdown is a viable option if you want it to happen at a specified time. If you want it to happen after a certain amount of time after you log in, you could use the number parameter to shutdown to specify say 8 hours from now.

这篇关于如何安全强制关闭Mac的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆