• L63.linux命令每日一练 -- 第九章 Linux进程管理命令 -- runlevel、init和service


    9.13 runlevel:输出当前运行级别

    9.13.1 命令详解

    【命令星级】 ★★★★★

    【功能说明】

    ​ runlevel命令用于输出当前Linux系统的运行级别。

    【语法格式】

    runlevel [option]
    runlevel [选项]
    
    • 1
    • 2

    ​ **说明:**在runlevel命令及后面的选项里,每个元素之间都至少要有一个空格。

    ​ 【选项说明】

    ​ 表9-14针对该命令的参数选项进行了说明。

    ​ 表9-14 runlevel命令的参数选项及说明
    在这里插入图片描述

    9.13.2 使用范例

    ​ **范例9-42:**查看当前系统的运行级别。

    [root@centos7 ~]# runlevel 
    N 3
    
    • 1
    • 2

    ​ 上面的结果说明当前的运行级别为3.对于系统级别,不同的数字代表的意思不一样,具体如下。

    • 0:停机
    • 1:单用户模式
    • 2:无王雷的多用户模式
    • 3:多用户模式
    • 4:未使用
    • 5:图形界面多用户模式
    • 6:重启

    9.14 init:初始化Linux进程

    9.14.1 命令详解

    【命令星级】 ★★★★★

    【功能说明】

    ​ init命令是Linux下的进程初始化工具,init进场是所有Linux进场的父进程,它的进程号为1。init命令的主要任务是依据配置文件“/etc/inittab”创建Linux进程。

    【语法格式】

    init [option]
    init [选项]
    
    • 1
    • 2

    ​ **说明:**在init命令及后面的选项里,每个元素之间都至少要有一个空格。

    9.14.2 使用范例

    ​ **范例9-43:**切换运行级别。

    [root@centos7 ~]# init 0	#关机,这里的数字含义请参考范例9-42的说明。
    [root@centos7 ~]# init 6	#重启。
    
    • 1
    • 2

    9.15 service:管理系统服务

    【命令星级】 ★★★★☆

    【功能说明】

    ​ service命令用于对系统服务进行管理,比如启动(start)、停止(stop)、重启(restart)、重新加载配置(reload)、查看状态(status)等,该命令在CentOS 7里被systemctl取代。

    【语法格式】

    service [script] [command]
    service [服务名] [执行命令]
    
    • 1
    • 2

    说明:

    ​ 1)在service命令及后面的服务名和执行命令里,每个元素之间都至少要有一个空格。

    ​ 2)command可选值有start、stop、restart、status、reload等。

    ​ 【选项说明】

    ​ 表9-15针对该命令的参数选项进行了说明。

    ​ 表9-15 service命令的参数选项及说明

    在这里插入图片描述

    9.15.2 使用范例

    ​ **范例9-44:**查看当前服务状态。

    [root@centos6 ~]# service --status-all	#显示所有服务状态。
    abrt-ccpp hook is installed
    abrt-dump-oops 已停
    abrtd (pid  1587) 正在运行...
    acpid (pid  1346) 正在运行...
    atd (pid  1629) 正在运行...
    auditd (pid  1151) 正在运行...
    automount (pid  1429) 正在运行...
    certmonger (pid  1646) 正在运行...
    Stopped
    cgred 已停
    cpuspeed 已停
    crond (pid  1614) 正在运行...
    cupsd (pid  1314) 正在运行...
    hald (pid  1358) 正在运行...
    htcacheclean 已停
    httpd 已停
    表格:filter
    Chain INPUT (policy ACCEPT)
    num  target     prot opt source               destination         
    1    ACCEPT     all      ::/0                 ::/0                state RELATED,ESTABLISHED 
    2    ACCEPT     icmpv6    ::/0                 ::/0                
    3    ACCEPT     all      ::/0                 ::/0                
    4    ACCEPT     udp      ::/0                 fe80::/64           state NEW udp dpt:546 
    5    ACCEPT     tcp      ::/0                 ::/0                state NEW tcp dpt:22 
    6    REJECT     all      ::/0                 ::/0                reject-with icmp6-adm-prohibited 
    
    Chain FORWARD (policy ACCEPT)
    num  target     prot opt source               destination         
    1    REJECT     all      ::/0                 ::/0                reject-with icmp6-adm-prohibited 
    
    Chain OUTPUT (policy ACCEPT)
    num  target     prot opt source               destination         
    
    表格:filter
    Chain INPUT (policy ACCEPT)
    num  target     prot opt source               destination         
    1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED 
    2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0           
    3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
    4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22 
    5    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
    
    Chain FORWARD (policy ACCEPT)
    num  target     prot opt source               destination         
    1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited 
    
    Chain OUTPUT (policy ACCEPT)
    num  target     prot opt source               destination         
    
    irqbalance 已停
    Kdump is not operational
    lvmetad 已停
    dmeventd 已停
    Checking for mcelog
    mcelog 已停
    mdmonitor 已停
    messagebus (pid  1293) 正在运行...
    mysqld (pid  2528) 正在运行...
    模块 netconsole 未被加载
    配置设备:
    lo eth0
    当前的活跃设备:
    lo eth0
    rpc.svcgssd 已停
    rpc.mountd 已停
    nfsd 已停
    rpc.rquotad 已停
    grep: /proc/fs/nfsd/portlist: 没有那个文件或目录
    rpc.statd (pid  1259) 正在运行...
    ntpd 已停
    numad 已停
    oddjobd 已停
    portreserve 已停
    master (pid  1573) 正在运行...
    进程记帐被禁用。
    quota_nld 已停
    rdisc 已停
    Low level hardware support loaded:
    	none found
    
    Upper layer protocol modules:
    	none found
    
    User space access modules:
    	none found
    
    Connection management modules:
    	none found
    
    rngd 已停
    rpcbind (pid  1236) 正在运行...
    rpc.gssd 已停
    rpc.idmapd 已停
    rpc.svcgssd 已停
    rsyslogd (pid  1185) 正在运行...
    sandbox is stopped
    saslauthd 已停
    smartd 已停
    openssh-daemon (pid  1494) 正在运行...
    sssd 已停
    winbindd 已停
    ypbind 已停
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103

    ​ **范例9-45:**管理系统服务。

    [root@centos6 ~]# service crond		#命令语句没有敲完时会显示帮助信息,crond是定时任务服务名。
    用法:/etc/init.d/crond 	#/etc/init.d/crond等同于service crond。
    {start|stop|status|restart|condrestart|try-restart|reload|force-reload}
    [root@centos6 ~]# service crond stop	#停止服务。
    停止 crond:                                               [确定]
    [root@centos6 ~]# service crond start	#启动服务。
    正在启动 crond:                                           [确定]
    [root@centos6 ~]# service crond restart	#重启服务。
    停止 crond:                                               [确定]
    正在启动 crond:                                           [确定]
    [root@centos6 ~]# service crond status 	#查看服务状态。
    crond (pid  5625) 正在运行...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    ​ 在工作中,推荐使用/etc/init.d/crond这个格式管理系统服务,因为这种格式支持tab键补齐,如果你忘记了服务名的书写,那就可以使用tab键。

    /etc/init.d/crond stop
    /etc/init.d/crond start
    /etc/init.d/crond restart
    /etc/init.d/crond status
    
    • 1
    • 2
    • 3
    • 4
  • 相关阅读:
    LeetCode 1175. 质数排列(质数判断+组合数学)
    React过渡动画
    车间动态调度的研究方法
    筑牢数据隐私安全底线,ADSCOPE通过ISO隐私信息管理体系认证!
    c语言基础知识帮助理解(函数递归详解)
    多模态大模型Claude 3正式接入集简云与语聚!对标GPT-4且支持中文
    振动监测:物联网预测性维护的“听诊器”
    两种解法解决 LeetCode 27. 移除元素【C++】
    ChatGPT桌面客户端支持gpt4模型,附使用说明
    金仓数据库 KingbaseGIS 使用手册(8.7. 栅格编辑函数、8.8. 栅格波段编辑函数)
  • 原文地址:https://blog.csdn.net/qq_25599925/article/details/126202671