2017年10月9日星期一

linux命令后台运行

http://www.cnblogs.com/lwm-1988/archive/2011/08/20/2147299.html

一、在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命令(效果与setid相同,但是disown后无法通过jobs命令查看了):
$ ./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 

linux中&、jobs、fg、bg等命令的使用方法

http://blog.sina.com.cn/s/blog_673ee2b50100iywr.html

一. & 最经常被用到
这个用在一个命令的最后,可以把这个命令放到后台执行
二. ctrl + z
可以将一个正在前台执行的命令放到后台,并且暂停
三. jobs
查看当前有多少在后台运行的命令
四. fg
将后台中的命令调至前台继续运行
如果后台中有多个命令,可以用 fg %jobnumber将选中的命令调出,%jobnumber是通过jobs命令查到的后台正在执行的命令的序号(不是pid)
五. bg
将一个在后台暂停的命令,变成继续执行
如果后台中有多个命令,可以用bg %jobnumber将选中的命令调出,%jobnumber是通过jobs命令查到的后台正在执行的命令的序号(不是pid)

2017年9月30日星期六

bazel build ... experimental文件夹不生效

bazel build ... 发现experimental中的没有编出来,猜测应该是bazel在递归查找的时候自动过滤了experimental的文件夹。

cd experimental
bazel build ...
进入experimental目录之后编是可以的。

2017年9月25日星期一

vim中200e unicode字符

参考https://unix.stackexchange.com/questions/59447/replace-unicode-chars-in-vim

先按ctrl-v,然后输入u200e可以输入<200e>字符。

:help i_CTRL-V_digit 可以查看一些帮助。

2017年9月21日星期四

mac安装node之后运行npm出错

module.js:341
    throw err;
    ^

Error: Cannot find module 'npmlog'
    at Function.Module._resolveFilename (module.js:339:15)
    at Function.Module._load (module.js:290:25)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:20:13
    at Object.<anonymous> (/usr/local/lib/node_modules/npm/bin/npm-cli.js:76:3)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)

因为之前卸载node没有卸载干净,解决方法:brew uninstall --force node
rm -rf /usr/local/lib/node_modules
rm /usr/local/bin/npm
brew install node

https://stackoverflow.com/a/39504056/5685754

pip install pyfst失败

Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-etZdYk/pyfst/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-9_TCLO-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-etZdYk/pyfst/

解决:
有人说export CFLAGS="-std=c++11",试了下,没用。

最后发现是版本问题,我安装的openfst是1.6.3版本,pyfst只支持到了1.3.3版本,再往上版本不兼容。

附,安装openfst:
./configure
make
sudo make install

安装完openfst运行时错误

fstinfo: error while loading shared libraries: libfstscript.so.8: cannot open shared object file: No such file or directory

解决:
在~/.bashrc中添加:
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib