易截截图软件、单文件、免安装、纯绿色、仅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启动(转载)

各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的地方,
而 ......

Ubuntu8.04下编译linux内核

今天看到师兄工位上有本Linux Kernel In a Nutshell,还是全英的影印版,所以就借过来看看,发现现在看英文的书渐渐适应了,还是比较容易的,书中开始介绍如何编译Linux内核,Linux内核大三的时候也学过编译过,但是当时编译比较简单,这次决定再重头到尾好好编译一下,首先下载linux kernel,再用secureCRT上传到Ubuntu 8. ......

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

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

linux桌面壁纸自动换(类似于windows7壁纸自动换)

复制以下内容,保存为  py 后缀的文件,拷贝到wallpaper文件夹,进入文件夹,以python运行,选取xml为壁纸
#!/usr/bin/env python2.6
# -*- coding: utf-8 -*-
# Ubuntu 9.10 dynamic wallpaper maker_Can be used in all the distributions of linux
#
# Auto generate a configuration file which you can use ......

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

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