linux进程不受终端影响
2015-07-23 16:33
651 查看
我们使用ssh连接服务器之后,如果在执行某个命令需要时间特别长,当把终端断掉之后,命令就自动停止了
一般我们在ssh客户端执行命令之后,默认他的父进程是ssh,所以把ssh终端关掉之后,子进程也就被自动kill掉了,解决办法就是更改这个命令进程的父进程为init,那样ssh退出去之后,命令依然会运行
默认情况下:
[root@localhost ~]# ping 127.0.0.1 &>/dev/null &
[1] 1782
[root@localhost ~]# pstree
init─┬─VBoxService───7*[{VBoxService}]
├─abrtd
├─acpid
├─atd
├─auditd───{auditd}
├─console-kit-dae───63*[{console-kit-da}]
├─crond
├─dbus-daemon
├─dhclient
├─hald───hald-runner─┬─hald-addon-acpi
│ └─hald-addon-inpu
├─master─┬─pickup
│ └─qmgr
├─6*[mingetty]
├─redis-server───2*[{redis-server}]
├─rsyslogd───3*[{rsyslogd}]
├─sshd───sshd───bash─┬─ping -------->从进程树中可以看出ping的父进程是ssh
│ └─pstree
└─udevd───udevd
解决办法:
1.使用nohup 即 nohup commond &
[root@localhost ~]# nohup ping 127.0.0.1 &>/dev/null &
查看进程:
[root@localhost ~]# pstree
init─┬─VBoxService───7*[{VBoxService}]
├─abrtd
├─acpid
├─atd
├─auditd───{auditd}
├─console-kit-dae───63*[{console-kit-da}]
├─crond
├─dbus-daemon
├─dhclient
├─hald───hald-runner─┬─hald-addon-acpi
│ └─hald-addon-inpu
├─master─┬─pickup
│ └─qmgr
├─6*[mingetty]
├─ping ---------->ping的父进程已经是init了
├─redis-server───2*[{redis-server}]
├─rsyslogd───3*[{rsyslogd}]
├─sshd───sshd───bash───pstree
└─udevd───udevd
2.使用setsid setsid commond &
[root@localhost ~]# setsid ping 127.0.0.1 &>/dev/null &
查看进程;
[root@localhost ~]# pstree
init─┬─VBoxService───7*[{VBoxService}]
├─abrtd
├─acpid
├─atd
├─auditd───{auditd}
├─console-kit-dae───63*[{console-kit-da}]
├─crond
├─dbus-daemon
├─dhclient
├─hald───hald-runner─┬─hald-addon-acpi
│ └─hald-addon-inpu
├─master─┬─pickup
│ └─qmgr
├─6*[mingetty]
├─ping ---------->ping的父进程已经是init了
├─redis-server───2*[{redis-server}]
├─rsyslogd───3*[{rsyslogd}]
├─sshd───sshd───bash───pstree
└─udevd───udevd
3.使用(), (commond &)
[root@localhost ~]# ( ping 127.0.0.1 &>/dev/null & )
查看进程树:
[root@localhost ~]# pstree
init─┬─VBoxService───7*[{VBoxService}]
├─abrtd
├─acpid
├─atd
├─auditd───{auditd}
├─console-kit-dae───63*[{console-kit-da}]
├─crond
├─dbus-daemon
├─dhclient
├─hald───hald-runner─┬─hald-addon-acpi
│ └─hald-addon-inpu
├─master─┬─pickup
│ └─qmgr
├─6*[mingetty]
├─ping ---------->ping的父进程已经是init了
├─redis-server───2*[{redis-server}]
├─rsyslogd───3*[{rsyslogd}]
├─sshd───sshd───bash───pstree
└─udevd───udevd
一般我们在ssh客户端执行命令之后,默认他的父进程是ssh,所以把ssh终端关掉之后,子进程也就被自动kill掉了,解决办法就是更改这个命令进程的父进程为init,那样ssh退出去之后,命令依然会运行
默认情况下:
[root@localhost ~]# ping 127.0.0.1 &>/dev/null &
[1] 1782
[root@localhost ~]# pstree
init─┬─VBoxService───7*[{VBoxService}]
├─abrtd
├─acpid
├─atd
├─auditd───{auditd}
├─console-kit-dae───63*[{console-kit-da}]
├─crond
├─dbus-daemon
├─dhclient
├─hald───hald-runner─┬─hald-addon-acpi
│ └─hald-addon-inpu
├─master─┬─pickup
│ └─qmgr
├─6*[mingetty]
├─redis-server───2*[{redis-server}]
├─rsyslogd───3*[{rsyslogd}]
├─sshd───sshd───bash─┬─ping -------->从进程树中可以看出ping的父进程是ssh
│ └─pstree
└─udevd───udevd
解决办法:
1.使用nohup 即 nohup commond &
[root@localhost ~]# nohup ping 127.0.0.1 &>/dev/null &
查看进程:
[root@localhost ~]# pstree
init─┬─VBoxService───7*[{VBoxService}]
├─abrtd
├─acpid
├─atd
├─auditd───{auditd}
├─console-kit-dae───63*[{console-kit-da}]
├─crond
├─dbus-daemon
├─dhclient
├─hald───hald-runner─┬─hald-addon-acpi
│ └─hald-addon-inpu
├─master─┬─pickup
│ └─qmgr
├─6*[mingetty]
├─ping ---------->ping的父进程已经是init了
├─redis-server───2*[{redis-server}]
├─rsyslogd───3*[{rsyslogd}]
├─sshd───sshd───bash───pstree
└─udevd───udevd
2.使用setsid setsid commond &
[root@localhost ~]# setsid ping 127.0.0.1 &>/dev/null &
查看进程;
[root@localhost ~]# pstree
init─┬─VBoxService───7*[{VBoxService}]
├─abrtd
├─acpid
├─atd
├─auditd───{auditd}
├─console-kit-dae───63*[{console-kit-da}]
├─crond
├─dbus-daemon
├─dhclient
├─hald───hald-runner─┬─hald-addon-acpi
│ └─hald-addon-inpu
├─master─┬─pickup
│ └─qmgr
├─6*[mingetty]
├─ping ---------->ping的父进程已经是init了
├─redis-server───2*[{redis-server}]
├─rsyslogd───3*[{rsyslogd}]
├─sshd───sshd───bash───pstree
└─udevd───udevd
3.使用(), (commond &)
[root@localhost ~]# ( ping 127.0.0.1 &>/dev/null & )
查看进程树:
[root@localhost ~]# pstree
init─┬─VBoxService───7*[{VBoxService}]
├─abrtd
├─acpid
├─atd
├─auditd───{auditd}
├─console-kit-dae───63*[{console-kit-da}]
├─crond
├─dbus-daemon
├─dhclient
├─hald───hald-runner─┬─hald-addon-acpi
│ └─hald-addon-inpu
├─master─┬─pickup
│ └─qmgr
├─6*[mingetty]
├─ping ---------->ping的父进程已经是init了
├─redis-server───2*[{redis-server}]
├─rsyslogd───3*[{rsyslogd}]
├─sshd───sshd───bash───pstree
└─udevd───udevd
相关文章推荐
- Linux socket 初步
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- 基于 Linux 集群环境上 GPFS 的问题诊断
- 谁是桌面王者?Win PK Linux三大镇山之宝
- vivi下重新调整分区
- Linux VS Unix:Linux欲一统天下 Unix不死
- linux下设定环境变量
- Linux下修改MySQL编码的方法