您的位置:首页 > 运维架构 > Linux

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

2017-12-06 16:29 453 查看

进程

查看进程

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...


查看端口号

法一:直接查询

[root@localhost ~]# netstat -nlp |grep 进程名


法二: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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: