1,关机命令 shutdown
1)shutdown --help
moon@moon-ThinkPad-Edge:~$ shutdown --help
用法: shutdown [OPTION]... 时间 [信息]
使系统关闭。
Options:
-r reboot after shutdown 现在立即重启
-h halt or power off after shutdown 关机
-H halt after shutdown (implies -h) 关机
-P power off after shutdown (implies -h) 该选项为缺省选项。就是关机时调用poweroff。
-c cancel a running shutdown
-k only send warnings, don't shutdown
-q, --quiet reduce output to errors only
-v, --verbose increase output to include informational messages
--help display this help and exit
--version output version information and exit
时间 可以使用不同的格式,最常用的是简单的一个单词
“now”,其使系统立即关闭。 其它可用的格式有 +m ,此 m
是关机前等待的分钟数;hh:mm 其指定以 24 小时制中的时间。
已登录的用户被一条发送到他们终端的一条消息警告,您可
包含一条可选的 消息 到此项中。 使用 -k
选项可以发送警告而不真的关机。
如果给出 时间 ,此命令将留在前端指导关机发生。
可以使用 Control-C 取消它,或者被其他用户以 -c 选项取消。
系统默认进入维护状态 (单用户) 模式,你可以使用 -r 或 -h
更改此行为,其分别指定系统重启或关闭。-h
选项可以进一步由 -H 或 -P
来指定伺候是关机还是切断电源。 默认动作由 shutdown
脚本决定。
Report bugs to <upstart-devel@lists.ubuntu.com>
2)halt—-最简单的关机命令
其实halt就是调用shutdown -h。halt执行时﹐杀死应用进程﹐执行sync系统调用﹐文件系统写操作完成后就会停止内核。
3)2中断命令
1)执行完命令后(若没有转到后台),可以使用CTRL+C来中止命令
2)kill 程序编码
当命令在后台执行时系统会返回一个程序编码,例如:在使用 shutdown -r 20:23 & 系统返回系统编码:4905
我们可以使用kill 4905来中止重启命令
3ps aux | grep 程序编号
我们如果知道程序的编号,我们可以使用ps aux |grep 程序编号来查询该程序编号对应的命令是什么。
例如上面的程序编号为4905 ,我们可以使用ps aux | grep 4905 就可以查到 shutdown -r 20:23 & 的命令
init
init是所有进程的祖先﹐它的进程号始终为1﹐所以发送TERM信号给init会终止所有的用户进程﹑守护进程等。shutdown 就是使用这种机制。init定义了8个运行级别(runlevel),init 0为关机﹐init 1为重启。关于init可以长篇大论﹐这里就不再叙述。另外还有telinit命令可以改变init的运行级别﹐比如﹐telinit -iS可使系统进入单用户模式﹐并且得不到使用shutdown时的信息和等待时间。
Android进程守护
1)同一个进程服务相互守护
public class Service01 extends Service {
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
System.out.println("我是服务01Service");
super.onCreate();
}
@Override
public void onDestroy() {
System.out.println("我是服务01,我被关闭了,开启01");
Intent intent = new Intent(this, Service02.class);
startService(intent);
super.onDestroy();
}
}
public class Service02 extends Service {
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
System.out.println("我是服务02Service");
super.onCreate();
}
@Override
public void onDestroy() {
System.out.println("我是服务02,我被关闭了,开启01");
Intent intent = new Intent(this, Service01.class);
startService(intent);
super.onDestroy();
}
}
/**
* 常驻内存
* 注册大量的广播接收者,常用广播;
* 锁屏广播
* 解锁屏幕
* 电话拨出
* 短信到来
*/