日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

OS X进程管理之launchctl

發(fā)布時間:2024/4/17 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OS X进程管理之launchctl 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
OS X進(jìn)程管理之launchctl
Apple官方文檔

如果 Mac 無法完成啟動,請嘗試安全模式

如果 Mac 無法開機(jī)應(yīng)如何處理

在 Mac OS X 中設(shè)置固件密碼保護(hù) 如何重置 Mac 上的 NVRAM 重置 Mac 上的系統(tǒng)管理控制器 (SMC) 在 Mac 上使用固件密碼
簡介 launchd之于OS X相對于Unix like系統(tǒng)而言如init,systemd,rc等,OS X的服務(wù)管理文件為.plist 關(guān)于launchctl可以man launchctl獲得詳細(xì)幫助
OS X級別開機(jī)啟動項.plist /Library/StartupItems/

/System/Library/StartupItems/



DEPRECATED AND REMOVED FUNCTIONALITY

?? ?launchctl no longer has an interactive mode, nor does it accept commands from stdin.

?? ? The /etc/launchd.conf file is no longer consulted for subcommands to run during early

?? ? boot time; this functionality was removed for security considerations. While it was

?? ? documented that $HOME/.launchd.conf would be consulted prior to setting up a user's

?? ? session, this functionality was never implemented.


?? ? launchd no longer uses Unix domain sockets for communication, so the LAUNCHD_SOCKET

?? ? environment variable is no longer relevant and is not set.


?? ?launchd no longer loads configuration files from the network


FILES

?? ? ~/Library/LaunchAgents ? ? ? ? Per-user agents provided by the user.

?? ? /Library/LaunchAgents? ? ? ? ? Per-user agents provided by the administrator.

?? ? /Library/LaunchDaemons ? ? ? ? System wide daemons provided by the administrator.

?? ? /System/Library/LaunchAgents ? OS X Per-user agents.

?? ? /System/Library/LaunchDaemons? OS X System wide daemons.



插曲--Mac Pro無法啟動

本來想禁止apache開機(jī)自啟動

launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist

結(jié)果太大意,沒想到手快了一步,命令敲成了

launchctl unload -w /System/Library/LaunchDaemons/

我的個乖乖,突然觸摸板,鍵盤全部失靈,有點(diǎn)慌了,怎么回事兒,還好有點(diǎn)linux基礎(chǔ),看了下命令,把系統(tǒng)的很多Daemons直接停掉并去除了開機(jī)啟動了,重啟后直接卡死在蘋果LOGO下,進(jìn)度好容易走完了,卻看不能美美的桌面,完了。真的是沒法加載相關(guān)Daemon從而加載硬件驅(qū)動,系統(tǒng)無法正常啟動。

問了下度娘,有說重新加載SMC的,詳風(fēng)蘋果官方文檔https://support.apple.com/zh-cn/HT201295

試了下,沒效果不說,反而風(fēng)扇狂轉(zhuǎn)不止,更加擔(dān)心了,難道要重裝,oh, my god


又百度了下,看了下無法啟動的基本排查思路和順序,理了理頭緒,既然是不小心去掉了開機(jī)啟動項,還原回去就可以了,于是


A方案(失敗)

進(jìn)Recovery模式,將unload掉的全部加入到開機(jī)啟動項后重啟

chroot /Volumes/Macintosh HD

cp -a System/Library/LaunchDaemons/* Library/StartupItems/

cp -a System/Library/LaunchDaemons/* System/Library/StartupItems/ exit launchctl reboot 失敗告終
B方案(成功) 如何以單用戶模式或詳細(xì)模式啟動 Mac 注意:進(jìn)入單用戶模式權(quán)限太大,太危險,可以為單用戶模式加道鎖,可選的組合方案如下 1.啟用FileVault,進(jìn)入單用戶模式時會要求輸入密碼確認(rèn)(性能比沒做磁盤加密肯定會低些) 2.設(shè)置固件密碼,阻止光盤,U盤等其它第三方介質(zhì)啟動,只有關(guān)閉固件密碼后才能進(jìn)入單用戶模式
Command+S進(jìn)入單用戶模式 說明:OS X也有單用戶模式,和linux很像,字符界面 以讀寫模式掛載根 mount -uw / launchctl load -w /System/Library/LaunchDaemons/ 只看到一大堆提示加載什么成功,之后便進(jìn)入到了美美的圖形界面,這時心里就有底了
可是問題來了 再次重啟,還是無法正常進(jìn)入圖形
想想,只是在單用戶模式下臨時加載了daemon而啟動到了多用戶圖形模式,而該模式(正常的圖形模式)并沒有將unload的daemon加入到開機(jī)啟動項,所以仍然無法正常啟動。于是, 重復(fù)上述動作進(jìn)入圖形后,再次執(zhí)行l(wèi)aunchctl load -wF /System/Library/LaunchDaemons/,讓圖形模式的開機(jī)啟動項中也有被unload掉的daemon 終于,再次重啟就一切回歸正常了,感謝萬能的度娘
man launchctl中有這么一小段,更加說明了此次無法正常啟動的緣由 簡單點(diǎn)講,就是放在/System/Library/LaunchDaemons某個第三方daemon可能導(dǎo)致系統(tǒng)無法正常啟動,而我的情況是/System/Library/LaunchDaemons下的所以daemon都被unload掉了,系統(tǒng)當(dāng)然無法正常啟動

Note that allowing non-root write access to the

? ? ? ? ? ? ?/System/Library/LaunchDaemons directory WILL render your system unbootable.


? ? ? ? ? ? ?-w ? ? ? Overrides the Disabled key and sets it to false or true for the

?? ? ? ? ? ? ? ? ? ? ? load and unload subcommands respectively. In previous versions,

?? ? ? ? ? ? ? ? ? ? ? this option would modify the configuration file. Now the state of

?? ? ? ? ? ? ? ? ? ? ? the Disabled key is stored elsewhere on- disk in a location that

?? ? ? ? ? ? ? ? ? ? ? may not be directly manipulated by any process other than launchd.



正題 常用的幾個launchctl命令 launchctl start|stop|list|remove label launchctl load|unload paths launchctl print|kickstart|kill|enable|disable?service-target
以apache為例 /System/Library/LaunchDaemons/org.apache.httpd.plist ? #就是path org.apache.httpd #就是label
1.daemon stop

jlive@MacBook-Pro:~ $su -

Password:

MacBook-Pro:~ root# ls /System/Library/LaunchDaemons/org.apache.httpd.plist?

/System/Library/LaunchDaemons/org.apache.httpd.plist

MacBook-Pro:~ root# ps -ef|grep httpd

? ? 0? ? 87 ? ? 1 ? 0 11:18PM ?? ? ? ? ? 0:01.56 /usr/sbin/httpd -D FOREGROUND

?? 70 ? 246? ? 87 ? 0 11:18PM ?? ? ? ? ? 0:00.03 /usr/sbin/httpd -D FOREGROUND

? ? 0? 3971? 3964 ? 0? 3:20PM ttys000? ? 0:00.00 grep httpd

MacBook-Pro:~ root# launchctl stop org.apache.httpd

MacBook-Pro:~ root# ps -ef|grep httpd

? ? 0? 3988? 3964 ? 0? 3:20PM ttys000? ? 0:00.00 grep httpd

2.daemon start

MacBook-Pro:~ root# launchctl start org.apache.httpd

MacBook-Pro:~ root# ps -ef|grep httpd

? ? 0? 4000 ? ? 1 ? 0? 3:23PM ?? ? ? ? ? 0:00.15 /usr/sbin/httpd -D FOREGROUND

?? 70? 4001? 4000 ? 0? 3:23PM ?? ? ? ? ? 0:00.00 /usr/sbin/httpd -D FOREGROUND

3.daemon list

MacBook-Pro:~ root# launchctl list|grep apache

4035 0 org.apache.httpd

? ? 0? 4003? 3964 ? 0? 3:23PM ttys000? ? 0:00.00 grep httpd

說明:load|unload并不一定會start|stop相關(guān)服務(wù),它只是在start或stop前載入相關(guān)配置環(huán)境

4.unload plist

MacBook-Pro:~ root# launchctl unload /System/Library/LaunchDaemons/org.apache.httpd.plist?

MacBook-Pro:~ root# ps -ef|grep httpd

? ? 0? 4237? 4221 ? 0? 4:01PM ttys001? ? 0:00.00 grep httpd

4.load plist

MacBook-Pro:~ root# launchctl load /System/Library/LaunchDaemons/org.apache.httpd.plist?

MacBook-Pro:~ root# ps -ef|grep httpd

? ? 0? 4241 ? ? 1 ? 0? 4:01PM ?? ? ? ? ? 0:00.16 /usr/sbin/httpd -D FOREGROUND

?? 70? 4243? 4241 ? 0? 4:01PM ?? ? ? ? ? 0:00.00 /usr/sbin/httpd -D FOREGROUND

? ? 0? 4245? 4221 ? 0? 4:01PM ttys001? ? 0:00.00 grep httpd

5.print service-target

MacBook-Pro:~ root# launchctl print system/org.apache.httpd|head

org.apache.httpd = {

active count = 1

path = /System/Library/LaunchDaemons/org.apache.httpd.plist

state = running


program = /usr/sbin/httpd-wrapper

arguments = {

/usr/sbin/httpd-wrapper

-D

?

FOREGROUND

6.kill service-target

MacBook-Pro:~ root# ps -ef|grep httpd

? ? 0?4417 ? ? 1 ? 0? 4:21PM ?? ? ? ? ? 0:00.16 /usr/sbin/httpd -D FOREGROUND

?? 70? 4423? 4417 ? 0? 4:21PM ?? ? ? ? ? 0:00.00 /usr/sbin/httpd -D FOREGROUND

? ? 0? 4429? 4221 ? 0? 4:21PM ttys001? ? 0:00.00 grep httpd

MacBook-Pro:~ root# launchctl kill SIGKILL system/org.apache.httpd

MacBook-Pro:~ root# ps -ef|grep httpd

? ? 0?4431 ? ? 1 ? 0? 4:21PM ?? ? ? ? ? 0:00.15 /usr/sbin/httpd -D FOREGROUND

?? 70? 4432? 4431 ? 0? 4:21PM ?? ? ? ? ? 0:00.00 /usr/sbin/httpd -D FOREGROUND

? ? 0? 4434? 4221 ? 0? 4:21PM ttys001? ? 0:00.00 grep httpd

7.disable service-target

MacBook-Pro:~ root# launchctl disable system/org.apache.httpd

MacBook-Pro:~ root# ps -ef|grep httpd

? ? 0? 4451? 4221 ? 0? 4:24PM ttys001? ? 0:00.00 grep httpd

MacBook-Pro:~ root# launchctl load /System/Library/LaunchDaemons/org.apache.httpd.plist?

/System/Library/LaunchDaemons/org.apache.httpd.plist: Service is disabled

8.enable service-target

MacBook-Pro:~ root# launchctl enable system/org.apache.httpd

MacBook-Pro:~ root# launchctl load /System/Library/LaunchDaemons/org.apache.httpd.plist?

MacBook-Pro:~ root# ps -ef|grep httpd

? ? 0? 4458 ? ? 1 ? 0? 4:25PM ?? ? ? ? ? 0:00.16 /usr/sbin/httpd -D FOREGROUND

?? 70? 4459? 4458 ? 0? 4:25PM ?? ? ? ? ? 0:00.00 /usr/sbin/httpd -D FOREGROUND

? ? 0? 4461? 4221 ? 0? 4:25PM ttys001? ? 0:00.00 grep httpd

轉(zhuǎn)載于:https://www.cnblogs.com/lixuebin/p/10814156.html

總結(jié)

以上是生活随笔為你收集整理的OS X进程管理之launchctl的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。