易截截图软件、单文件、免安装、纯绿色、仅160KB

如何让进程在Linux后台运行

在Linux中,如果要让进程在后台运行,一般情况下,我们在命令后面加上&即可,实际上,这样是将命令放入到一个作业队列中了:
[root@localhost /]# ./test.sh &
[1] 17208
然后我们就可以用以下命令进行查看:
[root@localhost /]# jobs -l
[1]  17208 Running ./test.sh &
对于已经在前台执行的命令,也可以重新放到后台执行首先按ctrl z暂停已经运行的进程,然后使用bg命令将停止的作业放到后台运行:
[root@localhost /]# bg %1
[1]  ./test.sh &
[root@localhost /]# jobs -l
[1]  22794 Running ./test.sh &
但是如上方到后台执行的进程,其父进程还是当前终端shell的进程,而一旦父进程退出,则会发送hangup信号给所有子进程,子进程收到hangup以后也会退出。如果我们要在退出shell的时候继续运行进程,则需要使用nohup忽略hangup信号,或者setsid将将父进程设为init进程(进程号为1)
[root@localhost /]# echo $$
21734
[root@localhost /]# nohup ./test.sh &amp;<br />
[1] 29016
[root@localhost /]# ps -ef | grep test
515 29710 21734 0 11:47 pts/12 00:00:00 /bin/sh ./test.sh
515 29713 21734 0 11:47 pts/12 00:00:00 grep test
[root@localhost /]# setsid ./test.sh &
[1] 409
[root@localhost /]# ps -ef | grep test
515 410 1 0 11:49 ? 00:00:00 /bin/sh ./test.sh
515 413 21734 0 11:49 pts/12 00:00:00 grep test
上面的试验演示了使用nohup/setsid加上&amp;使进程在后台运行,同时不受当前shell退出的影响。那么对于已经在后台运行的进程,该怎么办呢?可以使用disown命令:
[root@localhost /]# ./test.sh &
[1] 2539
[root@localhost /]# jobs -l
[1]  2539 Running ./test.sh &
[root@localhost /]# disown -h %1
[root@localhost /]# ps -ef | grep test
515 410 1 0 11:49 ? 00:00:00 /bin/sh ./test.sh
515 2542 21734 0 11:52 pts/12 00:00:00 grep test
另外还有一种方法,即使将进程在一个subshell中执行,其实这和setsid异曲同工。方法很简单,将命令用括号() 括起来即可:
[root@localhost /]# (./test.sh &)
[root@localhost /]# ps -ef | grep test
515 410 1 0 11:49 ? 00:00:00 /bin/sh ./test.sh
515 12483 21734 0 11:59 pts/12 00:00:00 grep test
注:本文试验环境为Red Hat Enterpr


相关文档:

Linux系统下修改MySQL的root密码

第一种方法:
root用户登录系统
usr/local/mysql/bin/mysqladmin -u root -p password 新密码
enter password 旧密码
第二种方法:
root用户登录mysql数据库
mysql> update mysql.user set password=password("新密码")where User="root";
mysql> flush privileges;
mysql> quit ;
mysql忘记root密码如何 ......

linux启动(转载)

各section的位置分布看内核的链接脚本
D:\KIDE\target\kernel-version\cgel3.0\linux\include\asm-generic\vmlinux.lds.h
D:\KIDE\target\kernel-version\cgel3.0\linux\arch\powerpc\kernel\vmlinux.lds.S
Kernel镜像起始地址KERNELBASE = 0xc000 0000,这意味着内核代码和内核全局变量等的地址空间在3g-4g的地方,
而 ......

redhat linux 9.0下LAMP的安装与配置

首先,服务器GCC要有,不然什么都不能做.能够用gcc -v来查看是否安装了GCC,
#gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.3/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
--enable-shared --enable-threads=posix --disable-checki ......

linux系统下NS 2(网络仿真开源软件)的安装

一.什么是NS 2
      NS 2是一种针对网络技术的源代码公开的、免费的软件模拟平台,研究人员使用它可以很容易的进行网络技术的开发,而且发展到今天,它所包含的模块非常丰富,几乎涉及到了网络技术的所有方面。
      NS 2(Network Simulator, version
2)是一种面 ......

嵌入式Linux文件系统及其存储机制分析

     嵌入式系统与通用PC机不同,一般没有硬盘这样的存储设备而是使用Flash闪存芯片、小型闪存卡等专为嵌入式系统设计的存储装置,本文分析了嵌入式系统中常用的存储设备及其管理机制,介绍了常用的基于FLASH的文件系统类型。
1.嵌入式系统存储设备及其管理机制分析
  构建适用于嵌入式系统的Li ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号