小技巧001-后台运行Linux程序
以运行icoFoam为例,当我们运行一个算例程序时,终端的输入输出渠道被占用,无法运行其他程序,使用VNCsever可以解决这一问题,但是需要新建termnial,并不方便,同时我们有时并不需要实时查看terminal的输出,只需要让icoFoam进行计算即可。
那么就可以使用这样一行命令:
nohup icoFoam > case.log &
nohup命令表示后面执行的程序不受终端关闭命令而关闭,这使得我们可以关闭terminal而不用担心程序被中断;
“>”符号表示将程序的输出定向到“case.log”文件中;
“&”符号表示程序在后台运行,不主动将输出定向到终端中。
如果想看到程序的实时输出信息,可以使用这一命令实时追踪:
tail -f case.log
如果不想查看,直接使用Ctrl+c关闭即可,并不影响计算。
当需要中断程序时,可以使用kill命令:
killall icoFoam
如果发起了多个同名的程序,请先使用top命令查看需要杀死的程序的PID号,使用命令“kill -9”杀死。
请放心,非root账号无法杀死其他用户的进程,例如:
top - 17:48:09 up 401 days, 8:40, 59 users, load average: 72.13, 72.38, 72.41 Tasks: 3386 total, 72 running, 3312 sleeping, 0 stopped, 2 zombie Cpu(s): 37.1%us, 2.2%sy, 0.0%ni, 60.6%id, 0.0%wa, 0.0%hi, 0.1%si, 0.0%st Mem: 132041796k total, 129034452k used, 3007344k free, 201288k buffers Swap: 4194300k total, 4194204k used, 96k free, 89236272k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 43380 ybwang 20 0 375m 69m 39m R 105.0 0.1 8171:05 twoPhaseEulerFo 20785 jiaying 20 0 303m 60m 35m R 103.6 0.0 2202:54 main 40797 ybwang 20 0 374m 66m 38m R 103.6 0.1 5666:34 twoPhaseEulerFo 43379 ybwang 20 0 376m 69m 39m R 103.6 0.1 7877:24 twoPhaseEulerFo 43382 ybwang 20 0 375m 68m 39m R 103.6 0.1 7962:37 twoPhaseEulerFo 40796 ybwang 20 0 375m 68m 38m R 102.1 0.1 6057:49 twoPhaseEulerFo 42141 ybwang 20 0 374m 67m 37m R 102.1 0.1 6003:45 twoPhaseEulerFo 42154 ybwang 20 0 379m 73m 37m R 102.1 0.1 7864:12 twoPhaseEulerFo 43373 ybwang 20 0 374m 67m 39m R 102.1 0.1 6211:34 twoPhaseEulerFo 43374 ybwang 20 0 375m 69m 39m R 102.1 0.1 5545:52 twoPhaseEulerFo 43381 ybwang 20 0 375m 69m 39m R 102.1 0.1 8203:15 twoPhaseEulerFo 40800 ybwang 20 0 376m 69m 38m R 100.7 0.1 6111:07 twoPhaseEulerFo 42155 ybwang 20 0 379m 72m 37m R 100.7 0.1 9058:50 twoPhaseEulerFo 42156 ybwang 20 0 379m 72m 37m R 100.7 0.1 7976:08 twoPhaseEulerFo 43364 ybwang 20 0 374m 67m 39m R 100.7 0.1 6114:08 twoPhaseEulerFo 20784 jiaying 20 0 306m 63m 36m R 99.2 0.0 1673:51 main 42143 ybwang 20 0 378m 71m 37m R 97.7 0.1 5388:22 twoPhaseEulerFo 42153 ybwang 20 0 375m 69m 37m R 97.7 0.1 6919:15 twoPhaseEulerFo 20780 jiaying 20 0 306m 64m 36m R 94.8 0.0 1451:50 main 20782 jiaying 20 0 306m 61m 36m R 94.8 0.0 1654:28 main 42152 ybwang 20 0 379m 73m 37m R 90.4 0.1 6289:00 twoPhaseEulerFo 42145 ybwang 20 0 379m 73m 37m R 84.6 0.1 6347:05 twoPhaseEulerFo 43370 ybwang 20 0 374m 68m 39m R 83.2 0.1 5655:51 twoPhaseEulerFo 20778 jiaying 20 0 306m 66m 36m R 80.2 0.1 1521:32 main 40803 ybwang 20 0 376m 70m 38m R 77.3 0.1 5532:58 twoPhaseEulerFo 42146 ybwang 20 0 375m 68m 37m R 77.3 0.1 5974:42 twoPhaseEulerFo 40802 ybwang 20 0 374m 67m 38m R 74.4 0.1 5839:50 twoPhaseEulerFo 20781 jiaying 20 0 306m 64m 36m R 72.9 0.0 1395:51 main 40813 ybwang 20 0 376m 69m 38m R 72.9 0.1 5915:36 twoPhaseEulerFo 43371 ybwang 20 0 374m 67m 39m R 72.9 0.1 5832:42 twoPhaseEulerFo 40801 ybwang 20 0 374m 68m 38m R 68.6 0.1 6147:35 twoPhaseEulerFo 20783 jiaying 20 0 306m 63m 36m R 67.1 0.0 1419:29 main 42149 ybwang 20 0 379m 72m 37m R 67.1 0.1 5801:12 twoPhaseEulerFo 43377 ybwang 20 0 375m 69m 39m R 67.1 0.1 5918:56 twoPhaseEulerFo 40807 ybwang 20 0 376m 69m 38m R 64.2 0.1 5824:01 twoPhaseEulerFo 40812 ybwang 20 0 375m 67m 38m R 64.2 0.1 6505:53 twoPhaseEulerFo 40805 ybwang 20 0 375m 68m 38m R 61.3 0.1 5863:21 twoPhaseEulerFo 40808 ybwang 20 0 375m 68m 38m R 61.3 0.1 5378:42 twoPhaseEulerFo 40811 ybwang 20 0 376m 69m 38m R 61.3 0.1 5137:27 twoPhaseEulerFo 42148 ybwang 20 0 378m 71m 37m R 61.3 0.1 5630:56 twoPhaseEulerFo 40806 ybwang 20 0 376m 69m 38m R 58.4 0.1 5645:31 twoPhaseEulerFo
[wli@K227 snappyTFM2]$ kill -9 43380 -bash: kill: (43380) - Operation not permitted
43380进程是ybwang的进程,wli用户无权限终结。
标签:ybwang,20,0.1,38m,twoPhaseEulerFo,001,Linux,后台,37m From: https://www.cnblogs.com/sub-group-IPE-wli/p/17206624.html