首页 > 编程知识 正文

进程控制块pcb的内容,进程控制块的作用

时间:2023-05-05 03:26:19 阅读:207330 作者:1614

MacOS不像 Linux 有 /etc/init.d/rc.local 以及 service 的方式可以设置程序随机启动,而是使用 plist 文件管理。你可以写一个plist文件放到~/Library/Launch Agents/下面,文件里描述你的程序路径和启动参数,那么这个用户登录时就会启动这个程序了,而且是杀不了的哦,被杀了之后会自动重新启动

plist文件分布在:

/System/Library/LaunchDaemons/ (System-wide daemons provided by OS X)
其中 apache的httpd程序启动配置文件 org.apache.httpd.plist 就在这里。/System/Library/LaunchAgents/ (由Mac OS X为用户定义的任务项)/Library/LaunchDaemons (由管理员定义的守护进程任务项 )/Library/LaunchAgents (由管理员为用户定义的任务项 )
如果放到/Library/Launch Agents/下面的话,就是一开机就启动哦~~/Library/LaunchAgents ( 由用户自己定义的任务项 )

这些配置文件由程序 launchctl 设置是否加载。
如果任务修改了,那么必须先unload,然后重新load;
launchctl start可以测试任务,这个是立即执行,不管时间到了没有;---- 测试发现没有效果。。。
执行 launchctl start 和 launchctl unload 前,任务必须先 load 过,否则报错;
launchctl stop 可以停止任务。

launchctl 简介

launchctl 管理 MacOS 的启动脚本,控制启动计算机时需要开启的服务。也可以设置定时执行特定任务的脚本,就像Linux cron一样。
launchctl需要root权限。

launchctl 常用命令 1.显示当前的启动脚本launchctl list launchctl list | grep 'com.hello' 使用 grep 过滤2.开机时自动启动Apache服务器sudo launchctl load -w /System/Library/LaunchDaemons/org.apache.httpd.plist3.设置开机启动并立即启动改服务launchctl load -w ~/Library/LaunchAgents/com.**.pist 4.设置开机启动但不立即启动服务 launchctl load ~/Library/LaunchAgents/com.**.pist 5. 移除正在运行的启动服务的脚本任务 launchctl unload ~/Library/LaunchAgents/com.**.plist6. 再加上-w选项即可去除启动服务的脚本任务 launchctl unload -w ~/Library/LaunchAgents/com.**.plist

####执行定时脚本|设置开机启动步骤
在Mac上可以像在Linux上一样,使用crontab来定时运行脚本,但苹果并不推荐这个方法。苹果推荐使用Launchctl来完成定时任务。

1.写执行脚本 (通过 brew 安装软件 brew 会为我们自动生成。)2. 去对应的目录下建立plist文件 3. 加载服务>1 cd 进入指定 plist 文件目录 >2 launchctl load *.plist #加载 launchctl unload *.plist #取消 >3 launchctl list #查看服务

####对服务设置别名方便操作
1. vim ~/.bash_profile #编辑添加如下脚本
2. 命名别名(以 nginx 为例)
>启动:alias nginx.start=’launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist’
>关闭:alias nginx.stop=’launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist’
>重启:alias nginx.restart=’nginx.stop && nginx.start’

####注意点

1. 在launchctl list 命令结果中出现的 plist 文件才会有效。
2. Agents文件夹下的plist是需要用户登录后,才会加载的,而Daemons文件夹下得plist是只要开机,可以不用登录就会被加载

####plist支持两种方式配置执行时间:

StartInterval:指定脚本每间隔多长时间(单位:秒)执行一次;
StartCalendarInterval:可以指定脚本在多少分钟、小时、天、星期几、月时间上执行,类似如crontab的中的设置,包含下面的 key:
Minute <integer> The minute on which this job will be run. Hour <integer> The hour on which this job will be run. Day <integer> The day on which this job will be run. Weekday <integer> The weekday on which this job will be run (0 and 7 are Sunday). Month <integer> The month on which this job will be run.
plist部分参数说明:

Label:对应的需要保证全局唯一性;
Program:要运行的程序;
ProgramArguments:命令语句
StartCalendarInterval:运行的时间,单个时间点使用dict,多个时间点使用 array
StartInterval:时间间隔,与StartCalendarInterval使用其一,单位为秒
StandardInPath、StandardOutPath、StandardErrorPath:标准的输入输出错误文件,这里建议不要使用 .log 作为后缀,会打不开里面的信息。
定时启动任务时,如果涉及到网络,但是电脑处于睡眠状态,是执行不了的,这个时候,可以定时的启动屏幕就好了。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。