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

Linux中如何让进程在后台运行


在Linux中,如果要让进程在后台运行,一般情况下,我们在命令后面加上&即可,实际上,这样是将命令放入到一个作业队列中了:
$ ./test.sh &
[1] 17208
$ jobs -l
[1]+ 17208 Running ./test.sh &
对于已经在前台执行的命令,也可以重新放到后台执行,首先按ctrl+z暂停已经运行的进程,然后使用bg命令将停止的作业放到后台运行:
$ ./test.sh
[1]+ Stopped ./test.sh
$ bg %1
[1]+ ./test.sh &
$ jobs -l
[1]+ 22794 Running ./test.sh &
但是如上方到后台执行的进程,其父进程还是当前终端shell的进程,而一旦父进程退出,则会发送hangup信号给所有子进程,子进程收到hangup以后也会退出。如果我们要在退出shell的时候继续运行进程,则需要使用nohup忽略hangup信号,或者setsid将将父进程设为init进程(进程号为1)
$ echo $$
21734
$ nohup ./test.sh &
[1] 29016
$ 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
$ setsid ./test.sh &
[1] 409
$ 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加上&使进程在后台运行,同时不受当前shell退出的影响。那么对于已经在后台运行的进程,该怎么办呢?可以使用disown命令:
$ ./test.sh &
[1] 2539
$ jobs -l
[1]+ 2539 Running ./test.sh &
$ disown -h %1
$ 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异曲同工。方法很简单,将命令用括号() 括起来即可:
$ (./test.sh &)
$ 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 Enterprise Linux AS release 4 (Nahant Update 5),shell为/bin/bash,不同的OS和shell可能命令有些不一样。例如AIX的ksh,没有disown,但是可以使用nohup -p&nb


相关文档:

添加Linux模块

有了系统调用的经验,添加模块还是很顺利的。
【实验环境】
Fedora,内核2.6.21.6
【实验步骤】
1. cd /root/homework/module
2. vi process.c
3. 加入如下代码:
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
static int process_init(void)
{
int num= ......

[Linux] 简单搭建校园FTP LINUX篇


http://www.myzqu.com/viewthread.php?tid=56258&extra=page%3D1%26amp;filter%3Dtype%26amp;typeid%3D199
linux, FTP, 搭建方法, 服务器
今天跟同学们说下怎么搭建校园FTP,以此来加强校内资源流通,在这个网络状况让人抓狂的今天,相信很有必要。。。   大家看了帖子就可以搭建自己的FT ......

Linux软件安装方法总结

1、软件安装 卸载,分几种情况:
A: RPM包,这种软件包就像windows的EXE安装 文件一样,各种文件已经编译好,并打了包,哪个文件该放到哪个文件夹,都指定好了,安装 非常方便,在图形界面里你只需要双击就能自动安装 。
==如何卸载:
1、打开一个SHELL终端
2、因为Linux 下的软件名都包括版本号,所以卸载前最好先确定 ......

Linux中如何新建用户


对于一般用户来说,主目录(home directory)是硬盘上唯一可以原来写东西的地方。一般的路径名是/home/login_user_name。
主目录用于存储各种用户文件:设置文件,程序配置文件,用户文档,数据 netscape 的缓存,邮件等等。作为一个普通用户,你可以在主目录下建立新的目录安排你自己的目录结构。其他用户无法阅读你的 ......

linux下apache+php安装常见问题


configure: error: Unable to find libgd.(a|so)
如果使用的是ubuntu或debian就很简单了,直接sudo apt-get install apache2
libapache2-mod-php5 php5 php5-gd 就基本上搞定,但是用源代码安装还是很麻烦~
wget http://www.boutell.com/gd/http/gd-2.0.11.tar.gz
tar zxvf gd-2.0.11.tar.gz
cd gd-2.0.11
sudo . ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号