linux常用指令(3)——进程、环境变量配置

进程

查看进程

ps -ef | grep 进程名  #显示和进程有关的进程

如:

[root@localhost ~]# ps -ef | grep ntp
ntp       2607     1  0 23:13 ?        00:00:00 ntpd -u ntp:ntp -p /var/run/ntpd.pid -g
root      2618  2502  0 23:14 pts/0    00:00:00 grep ntp

字段含义如下:

UIDPIDPPIDCSTIMETTYTIMECMD
root26182502023:14pts/000:00:00grep ntp

- UID :程序被该 UID 所拥有
- PID :这个程序的 ID
- PPID :这个程序上级父程序的ID
- C :CPU使用的资源百分比
- STIME :系统启动时间
- TTY :登入者的终端机位置
- TIME :使用掉的 CPU 时间。
- CMD :所下达的指令为何

终止进程

kill [参数] [进程名]

一般直接使用 kill -9 进程名 来结束进程, -9 表示强制终止

[root@localhost ~]# kill -9 2607
[root@localhost ~]# ps -ef | grep ntp
root      2618  2502  0 23:14 pts/0    00:00:00 grep ntp

可以看出ntp这个进程已经被终止。

开启进程

开启ntp进程

#检查ntp有无开启
[root@localhost ~]# service ntpd status
ntpd is stopped #表示没有开启ntpd进程
#开启ntp
[root@localhost ~]# service ntpd start
Starting ntpd:                         [ OK]
#检查ntp有无开启
[root@localhost ~]# service ntpd status
ntpd (pid 2607)is running...

查看端口号

  1. 法一:直接查询
[root@localhost ~]# netstat -nlp |grep 进程名
  1. 法二:pid查询
[root@localhost ~]# ps -ef | grep 进程名 #先得到进程的pid
[root@localhost ~]# netstat -nlp |grep pid  #利用pid得到端口号

[root@localhost ~]# netstat -nlp |grep ntp
#根据ps -ef | grep ntp得到的pid是2607
[root@localhost ~]# ps -ef|grep 2607

上述两种方法得到的结果都是:

udp        0      0 192.168.252.128:123         0.0.0.0:*                               2607/ntpd           
udp        0      0 127.0.0.1:123               0.0.0.0:*                               2607/ntpd           
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               2607/ntpd           
udp        0      0 fe80::20c:29ff:fe25:1f0b:123 :::*                                    2607/ntpd           
udp        0      0 ::1:123                     :::*                                    2607/ntpd           
udp        0      0 :::123                      :::*                                    2607/ntpd 

可以知道ntp的端口号是123

环境变量配置

权限进入环境变量生效配置
全局 vi /etc/profile source /etc/profile
个人vi ~/.bash_profilesource .bash_profile(.bashrc)
vi ~/.bashrc. .bash_profile(.bashrc)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值