将进程放入后台的方法---disown

disown

场景:

我们已经知道,如果事先在命令前加上 nohup 或者 setsid 就可以避免 HUP 信号的影响。但是如果我们未加任何处理就已经提交了命令,该如何补救才能让它避免 HUP 信号的影响呢?

解决方法:

这时想加 nohup 或者 setsid 已经为时已晚,只能通过作业调度和 disown 来解决这个问题了。让我们来看一下 disown 的帮助信息:

disown [-ar] [-h] [jobspec ...]
	Without options, each jobspec is  removed  from  the  table  of
	active  jobs.   If  the -h option is given, each jobspec is not
	removed from the table, but is marked so  that  SIGHUP  is  not
	sent  to the job if the shell receives a SIGHUP.  If no jobspec
	is present, and neither the -a nor the -r option  is  supplied,
	the  current  job  is  used.  If no jobspec is supplied, the -a
	option means to remove or mark all jobs; the -r option  without
	a  jobspec  argument  restricts operation to running jobs.  The
	return value is 0 unless a jobspec does  not  specify  a  valid
	job.

可以看出,我们可以用如下方式来达成我们的目的。

灵活运用 CTRL-z
在我们的日常工作中,我们可以用 CTRL-z 来将当前进程挂起到后台暂停运行,执行一些别的操作,然后再用 fg 来将挂起的进程重新放回前台(也可用 bg 来将挂起的进程放在后台)继续运行。这样我们就可以在一个终端内灵活切换运行多个任务,这一点在调试代码时尤为有用。因为将代码编辑器挂起到后台再重新放回时,光标定位仍然停留在上次挂起时的位置,避免了重新定位的麻烦。
  • disown -h jobspec 来使某个作业忽略HUP信号。
  • disown -ah 来使所有的作业都忽略HUP信号。
  • disown -rh 来使正在运行的作业忽略HUP信号。

需要注意的是,当使用过 disown 之后,会将把目标作业从作业列表中移除,我们将不能再使用jobs来查看它,但是依然能够用ps -ef查找到它。

但是还有一个问题,这种方法的操作对象是作业,如果我们在运行命令时在结尾加了"&"来使它成为一个作业并在后台运行,那么就万事大吉了,我们可以通过jobs命令来得到所有作业的列表。但是如果并没有把当前命令作为作业来运行,如何才能得到它的作业号呢?答案就是用 CTRL-z(按住Ctrl键的同时按住z键)了!

CTRL-z 的用途就是将当前进程挂起(Suspend),然后我们就可以用jobs命令来查询它的作业号,再用bg jobspec 来将它放入后台并继续运行。需要注意的是,如果挂起会影响当前进程的运行结果,请慎用此方法。


disown 示例1(如果提交命令时已经用“&”将命令放入后台运行,则可以直接使用“disown”)
                
[root@pvcent107 build]# cp -r testLargeFile largeFile &
[1] 4825
[root@pvcent107 build]# jobs
[1]+  Running                 cp -i -r testLargeFile largeFile &
[root@pvcent107 build]# disown -h %1
[root@pvcent107 build]# ps -ef |grep largeFile
root      4825   968  1 09:46 pts/4    00:00:00 cp -i -r testLargeFile largeFile
root      4853   968  0 09:46 pts/4    00:00:00 grep largeFile
[root@pvcent107 build]# logout   


disown 示例2(如果提交命令时未使用“&”将命令放入后台运行,可使用 CTRL-z 和“bg”将其放入后台,再使用“disown”)
                
[root@pvcent107 build]# cp -r testLargeFile largeFile2

[1]+  Stopped                 cp -i -r testLargeFile largeFile2
[root@pvcent107 build]# bg %1
[1]+ cp -i -r testLargeFile largeFile2 &
[root@pvcent107 build]# jobs
[1]+  Running                 cp -i -r testLargeFile largeFile2 &
[root@pvcent107 build]# disown -h %1
[root@pvcent107 build]# ps -ef |grep largeFile2
root      5790  5577  1 10:04 pts/3    00:00:00 cp -i -r testLargeFile largeFile2
root      5824  5577  0 10:05 pts/3    00:00:00 grep largeFile2
[root@pvcent107 build]#   

Posted by microsea


Trackback URL : 无法向此文章发送引用

运行perl程序时出现: bad interpreter: No such file or directory 这样的错误提示.

原因:这是在windows下通过写字板或其他编辑工具编写的perl程序,windows环境下每行的结束符是CRLF(Carriage-Return, Line-Feed). 在linux下结束符却是LF,所以每行多了一个CR串.
处理:通过以下脚本对每行结束符进行替换
#!/usr/bin/perl

die "Usage: $0 < files >\n" unless @ARGV;

for $file (@ARGV)
{
    open IN, $file or die "$0: Cannot open $file for input!\n";

    my @lines = <IN>;

    close IN;
    open OUT, "> $file" or die "$0: Cannot open $file for output!\n";

    s/\r$// for @lines;
    print OUT for @lines;
}

Posted by microsea


Trackback URL : 无法向此文章发送引用

Leave a comment
[emerg] (28)No space left on device: Couldn't create accept lock
or
[crit] (28)No space left on device: mod_rewrite: could not create rewrite_log_lock Configuration Failed
or
[error] (28)No space left on device: Cannot create SSLMutex
处理方法:
ipcs -s | grep apache | perl -e 'while (&lt;STDIN&gt;) { @a=split(/\s+/); print `ipcrm sem $a[1]`}'
==============
ipcs -s | grep apache | awk ' { print $2 } ' | xargs ipcrm sem

Posted by microsea


Trackback URL : 无法向此文章发送引用

将mysql4.x gb2312 数据库导入到 mysql5.x

经过尝试,原mysql4.x数据库字符集为GB2312,保持GB2312不转换为UTF-8,导出并导入到mysql5.x的步骤如下:
1.导出数据:
/usr/bin/mysqldump -u root --socket=/data/answer/mysql.sock answer > `date +'%Y_%m_%d'`answer.sql
导出文件命名为当天日期+数据库名.sql

2.编辑xxx.sql文件,在头几行可以找到:
/*!40101 SET NAMES utf8 */;
更改为:
/*!40101 SET NAMES GB2312 */;

3.启动mysql5的参数增加--default-character-set=gb2312,如下脚本:
#!/bin/sh
cd /mysqldata/bk.17173.com
rundir=`dirname "$0"`
echo "$rundir"
/usr/local/mysql/bin/safe_mysqld --default-character-set=gb2312 --user=mysql --skip-name-resolve --skip-innodb --skip-locking --pid-file="$rundir"/mysql.pid --datadir="$rundir" -O log-slow-queries=slow_query.txt -O back_log=500 -O interactive_timeout=60  -O max_connections=6400 -O record_buffer=16M -O max_connect_errors=1000 -O sort_buffer_size=128M -O sort_buffer=128M -O table_cache=256M -O thread_cache_size=80 -O wait_timeout=30 -O query_cache_size=64M -O key_buffer_size=128M  -O key_buffer=128M --port=3308 -O myisam_sort_buffer_size=128M --socket="$rundir"/mysql.sock &

4.登陆mysql,然后执行:
set character_set_client=gb2312;
set character_set_connection=gb2312;
set character_set_database=gb2312;
set character_set_results=gb2312;
set character_set_server=gb2312;

5.导入数据库:
source xxx.sql;

Posted by microsea


Trackback URL : 无法向此文章发送引用

Comments List

  1. 秘密访客 2008/January/05-13:35 # M/D Reply

    只有管理员能看到的回复.

  2. live audio streamin 2008/May/23-03:27 # M/D Reply

    나는 합의한다 너에 이다. 그것은 이렇게 이다.

  3. greensboro ywca 2008/May/23-03:57 # M/D Reply

    여기 이것은 뉴스 있다!

  4. charity hodges amaz 2008/May/23-04:29 # M/D Reply

    너는 위치를차가운 만들었다!

  5. high heels nylon fe 2008/May/23-06:05 # M/D Reply

    걸출한 뉴스!! 종류 블로그!

  6. red headed slut sho 2008/May/23-06:51 # M/D Reply

    여기 이것은 뉴스 있다!

  7. pamela anderson pre 2008/May/23-23:09 # M/D Reply

    너는 위치가 우수한 있는다!

  8. hairy skinny nudes 2008/May/23-23:13 # M/D Reply

    블로그를 위한 감사합니다.

  9. drink recipe for pa 2008/May/23-23:30 # M/D Reply

    걸출한 뉴스!! 종류 블로그!

Leave a comment

ImageMagick + magickwand for PHP 安装手记

网上流传的安装方法都有问题,在configure PHP的时候会出错!

还是按自己摸索的方法安装才成功,给大家分享一下.

首先要选择6.2.6以上版本,magickwand INSTALL说的支持6.2.4-1版本似乎有点问题,我编译不过.



1.安装ImageMagick

tar –zxvf ImageMagick-6.2.6-5.tar.gz

cd ImageMagick-6.2.6

./configure LDFLAGS="-L/usr/lib" CPPFLAGS="-I/usr/include" --prefix=/usr/local/ImageMagick --enable-shared --enable-lzw

make

make install

2.安装PHP

tar –zxvf php-4.3.6.tar.gz

cd php-4.3.6

./configure --with-png-dir=/usr --with-gd --enable-gd-native-ttf --with-ttf --with-freetype --without-gdbm --with-gettext --with-ncurses --with-gmp --with-iconv --with-jpeg-dir=/usr  --with-png --enable-ftp --enable-sockets -with-xml --with-dom --with-zlib --enable-track-vars --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache2/bin/apxs

make

make install

说明:不带--with-imagick=/usr/local/ImageMagick参数先安装一下PHP,之后要用到phpize命令.

3.安装magickwand-0.1.8

unzip magickwand-0.1.8.zip

mv magickwand php-4.3.6/ext/

cd php-4.3.6/ext/magickwand

phpize

cd ../../

rm -rf configure

./buildconf –force

export PATH=${PATH}:/usr/local/ImageMagick/bin

#关键一步,否则编译无法通过,会有这样错误误导你:

[CODE].......... checking for ImageMagick / MagickWand in provided path... found in /usr/local/ImageMagick checking for ImageMagick / MagickWand 6.2.4 or greater with /usr/local/ImageMagick/bin/Wand-config... 6.2.6 /usr/local/ImageMagick/bin/Wand-config: line 42: Magick-config: command not found /usr/local/ImageMagick/bin/Wand-config: line 39: Magick-config: command not found ........... ........... checking size of char... configure: error: cannot compute sizeof (char), 77 See `config.log' for more details.[/CODE]

./configure --with-png-dir=/usr --with-gd --enable-gd-native-ttf --with-ttf --with-freetype --without-gdbm --with-gettext --with-ncurses --with-gmp --with-iconv --with-jpeg-dir=/usr  --with-png --enable-ftp --enable-sockets -with-xml --with-dom --with-zlib --enable-track-vars --with-mysql=/usr/local/mysql --with-imagick=/usr/local/ImageMagick --with-apxs2=/usr/local/apache2/bin/apxs

make

make install

补充问题:
如果MagickWand 执行./configure 时,出现checking for MagickSetImageTicksPerSecond in -lWand… NO的错误,可能是您现在安装了两个版本的ImageMagick,且默认的版本低于ImageMagick-6.3.3
可以用Magick-config –version命令查看其版本。
通常是系统安装了rpm包,解决方法是卸载掉libImageMagick包:
rpm -qa | grep 'ImageMagick'
rpm -e ImageMagick*


剩下不多说了的参考PHP+apache的安装文档.

成功后在phpinfo()里可以看到:

Posted by microsea


Trackback URL : 无法向此文章发送引用

Comments List

  1. gay teenboy stories 2008/May/23-03:29 # M/D Reply

    그런 위치를 경이롭 위해 많게의 감사!

  2. sexiest games for t 2008/May/23-04:07 # M/D Reply

    나는 배웠다 매우…

  3. mature movie sex 2008/May/23-04:34 # M/D Reply

    아주 좋은 나는 위치 그것을 감사 좋아한다!

  4. public speaking for 2008/May/23-05:05 # M/D Reply

    좋은 너를 위치! 감사하십시요.

  5. naked old men gallo 2008/May/23-06:14 # M/D Reply

    아주 유용한 정보!

  6. candy loving galler 2008/May/23-23:25 # M/D Reply

    친구는 너의 현재 위치의 팬이 되었다!

  7. sybian story 2008/May/23-23:31 # M/D Reply

    일! 우수한 감사!

  8. girls violet wonka 2008/May/23-23:33 # M/D Reply

    블로그를 위한 감사합니다.

  9. big women dating 2008/May/23-23:41 # M/D Reply

    여보세요, 좋은 아주 위치!

Leave a comment

跟踪进程查看问题所在--strace/truss

APACHE error.log中产生了
[Wed Apr 25 21:13:54 2007] [notice] child pid 3204604 exit signal Segmentation fault (11)


使用以下脚本跟踪一下apache的进程,看是什么页面或程序引起的

#!/bin/sh
while [ "1" == "1" ]; do
        APACHE_LIST=`ps -ef | grep apache |grep -v grep|awk '{ print $2; }'` 
        for i in $APACHE_LIST; do   
                if [ ! -e $i.log ]; then     
                        echo "strace $i"     
                        strace -p $i 2> $i.log &   
                fi 
        done

        echo "wait" 
        sleep 60s
done


出现Segmentation fault信息的时候,打开该PID的log文件,查看含有Segmentation fault信息的前面几行是打开或操作什么文件,再查相应原因.

more..

Posted by microsea


Trackback URL : 无法向此文章发送引用

Leave a comment

Perl常见特殊变量

Perl常见特殊变量

1. $_
$ARG,常常是一个默认变量

2. @_
@ARG,子例程参数表

3. {row.content}
$PROGRAM_NAME,本程序的名字

4. @ARGV
本程序的命令行参数表

more..

Posted by microsea


Trackback URL : 无法向此文章发送引用

Leave a comment

AS5 下安装apache 2.0.x时碰到的问题

AS4上安装正常的apache 2.0.5x版本在AS5下编译会出错:
/usr/lib/libexpat.so: could not read symbols: File in wrong format

解决方法:
1. 配置命令:./configure 时加入 LDFLAGS="-L/usr/lib64 -L/lib64"

2. 修改{apache-src-dir}/srclib/apr-util/Makefile:


APRUTIL_LIBS = -lsqlite3 /usr/lib/libexpat.la /root/tar/httpd-2.2.3/srclib/apr/libapr-1.la -luuid -lrt -lcrypt -lpthread -ldl
改为
APRUTIL_LIBS = -lsqlite3 /usr/lib64/libexpat.la /root/tar/httpd-2.2.3/srclib/apr/libapr-1.la -luuid -lrt -lcrypt -lpthread -ldl

3. make; make install

Posted by microsea


Trackback URL : 无法向此文章发送引用

Leave a comment

不同版本mysql并存实例

当不同版本MYSQL在同一台服务器上运行时需要注意的:
1.不同版本库的数据存放目录要独立
2.各自配置文件要独立
3.执行命令要指定各自版本的具体路径
4.日志文件要明确指定
实例步骤:
1. 首先将不同版本MYSQL安装在不同目录下:
MYSQL 4.0.20 安装目录为: /usr/local/mysql4020
MYSQL 5.0.22安装目录为: /usr/local/mysql5022

more..

Posted by microsea


Trackback URL : http://www.givingtree.com.cn/trackback/347

Leave a comment
UPGRADED MY FAVORITE TOOLS SecureCRT & SecureFX TODAY.
BELOW IS THE CHANGES OF THEM AND THE DOWNLOAD LINKS,INCLUDE CRACKED PATCH.CLICK "MORE" FOR DETAIL.

more..

Posted by microsea


Trackback URL : http://www.givingtree.com.cn/trackback/345

Comments List

  1. lesbian scissoring 2008/May/23-03:29 # M/D Reply

    재미있는 아주 지점. 감사.

  2. vintage backpacking 2008/May/23-03:56 # M/D Reply

    뉴스를 위한 감사합니다…

  3. dominatrix training 2008/May/23-04:21 # M/D Reply

    많은 감사 위치! 우수한 나는 너의.

  4. peeing pictures gir 2008/May/23-04:56 # M/D Reply

    친구는 너의 현재 위치의 팬이 되었다!

  5. kingwood high schoo 2008/May/23-06:24 # M/D Reply

    여보세요, 좋은 아주 위치!

  6. extreme topless fig 2008/May/23-06:40 # M/D Reply

    너는 위치를차가운 만들었다!

  7. soapy punishment en 2008/May/24-00:32 # M/D Reply

    우수한과 아주 도움이 되는!

Leave a comment

tar xvzf mod_fastcgi-2.4.2.tar.gz
cd mod_fastcgi-2.4.2
cp Makefile.AP2 Makefile
make
出现:

mod_fastcgi.c: In function `init_module':
mod_fastcgi.c:270: error: `ap_null_cleanup' undeclared (first use in this function)
mod_fastcgi.c:270: error: (Each undeclared identifier is reported only once
mod_fastcgi.c:270: error: for each function it appears in.)
mod_fastcgi.c: In function `process_headers':
............

等错误,
下载附件到mod_fastcgi目录
执行 patch -p1 < patch
再make && make install

备注:fastcgi下载地址: http://www.fastcgi.com/dist/

Posted by microsea


Trackback URL : http://www.givingtree.com.cn/trackback/343

Leave a comment
REDHAT AS4 64位系统下编译安装net-snmp 5.4 by microsea
 
一.安装:
# configure --enable-mfd-rewrites # make; # make install
在64位系统下,如果直接make会出现以下错误:
/bin/sh ../libtool  --mode=link gcc -g -O2 -Dlinux -I/usr/include/rpm  -o snmpd snmpd.lo    libnetsnmpmibs.la libnetsnmpagent.la helpers/libnetsnmphelpers.la  ../snmplib/libnetsnmp.la -ldl -lrpm -lrpmio -lpopt  -lz -lcrypto -lm
gcc -g -O2 -Dlinux -I/usr/include/rpm -o .libs/snmpd snmpd.o  ./.libs/libnetsnmpmibs.so ./.libs/libnetsnmpagent.so helpers/.libs/libnetsnmphelpers.so ../snmplib/.libs/libnetsnmp.so -ldl -lrpm -lrpmio /usr/lib/libpopt.so -lz -lcrypto -lm  -Wl,--rpath -Wl,/usr/local/lib
/usr/lib/libpopt.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
make:*** [service:snmpd] Error 1
需要修改以下两个文件:

more..

Posted by microsea


Trackback URL : 无法向此文章发送引用

Comments List

  1. large rubber ducky 2008/May/23-03:43 # M/D Reply

    걸출한 디자인! 좋은 디자인.

  2. skin tight cycling 2008/May/23-04:13 # M/D Reply

    너는 위치가 우수한 있는다!

  3. cheerleader fucked 2008/May/23-04:23 # M/D Reply

    좋은 너를 위치! 감사하십시요.

  4. slavegirls sex 2008/May/23-05:51 # M/D Reply

    여보세요, 좋은 아주 위치!

  5. coyote ugly soundtr 2008/May/23-06:14 # M/D Reply

    걸출한 블로그!

  6. gay sex online 2008/May/23-06:39 # M/D Reply

    나는 배웠다 매우…

  7. laguna beach breast 2008/May/24-00:09 # M/D Reply

    좋은 영역! 걸출한 영역!

  8. anime channel 2008/May/24-00:15 # M/D Reply

    너는 아주 보는 좋은 위치가 있는다!

  9. campus lodge apartm 2008/May/24-00:20 # M/D Reply

    정보를 위한 감사합니다.

  10. adult message mates 2008/May/24-00:27 # M/D Reply

    블로그를 위한 감사합니다.

Leave a comment

MYSQL replication/cluster links

howtoForge linux HA refs:
part. MySQL

How To Set Up A Load-Balanced MySQL Cluster

How To Set Up Database Replication In MySQL

http://kb.discuz.net/index.php?title=MySQL-Cluster%E9%9B%86%E7%BE%A4%E7%A0%94%E7%A9%B6

http://flutey.3322.org/node/81

http://blog.chinaunix.net/u/5591/showart_306240.html

Posted by microsea


Trackback URL : 无法向此文章发送引用

Leave a comment

关于MYSQL的性能调整,下面的文章提供了不错的建议.

What to tune in MySQL Server after installation

more..