愤怒的青年分享 http://blog.sciencenet.cn/u/NanoZhang

博文

如何在Linux中做批处理和后台计算

已有 9918 次阅读 2012-3-6 13:44 |系统分类:科研笔记| Linux, 后台, 计算, 批处理

单个计算任务的提交
 
How to compute by Gaussian 03?
1. Upload "xxx.gjf" to your folder.
2. Perform "g03 xxx.gjf &" in your folder.
3. See your tasks by "jobs", it's running. Ok!
 
How to run a Fortran code?
1. Upload "xxx.f90" to your folder.
2. Perform "gfortran xxx.f90 -o xxx" in your folder.
3. Perform "./xxx &".
4. See your tasks by "jobs", it's running. Ok!
 
How to stop a running task?
1. Perform "ps" or "top", find the "pid" corresponging to the task you want to stop.
2. Perform "kill -9 pid", if not, perform "kill -15 pid".
3. See your tasks by "jobs", it disappears. Ok!
 
多个计算任务依次执行(即批处理)
 
以Gaussian计算为例,新建一个文件,比如batch,不需要文件类型扩展名。输入如下内容:
g03 xx1.gjf
g03 xx2.gjf
……
执行“chmod u+x batch”改变其权限,使其可执行。
如果不是unix格式,就使用“dos2unix batch”把Windows格式转换到Unix格式。
执行“./batch &”。Ok!
 
让任务在后台运行
 
在我的机子测试中,仅仅按上面的操作,即只在命令末尾加“&”,就可以在后台运行了。如果不行,还可以使用下面的方法。以Gaussian计算为例
1. nohup方法:"nohup g03 xxx.gjf &"
2. setsid方法:"setsid g03 xxx.gjf"
3. ()方法:"(g03 xxx.gjf &)"
4. 补救措施。把已经提交的任务转到后台运行。
"disown -h %n" n是作业号,利用jobs查看
"disown -ah" 使所有的作业都忽略HUP信号
"disown -rh" 使正在运行的作业忽略HUP信号
5. screen方法
如果有大量的任务需要在后台运行,又不想每次都使用上面的命令这么麻烦,可以使用screen方法。
 
注意:用终端提交完任务后,用logout或exit正常退出,别直接点右上角的叉叉,否则会出现后台命令失效的情况。
 
其他常用命令
 
1. 查看cpu “cat /proc/cpuinfo”
   物理CPU数 “cat /proc/cpuinfo | grep 'physical id' | sort | uniq | wc -l”
   每个CPU的核数 “cat /proc/cpuinfo | grep 'physical id' | grep '0' | wc -l”
   逻辑CPU数“cat /proc/cpuinfo | grep 'processor' | wc -l”
   (写作格式:“grep 'model name' /proc/cpuinfo”)
2. 查看Linux版本 “cat /proc/version”、“uname -a”
3. 查看操作系统版本 “cat /etc/issue”
4. 查看操作系统位数 “arch”、“uname -m”、“getconf LONG_BIT”、“cat /proc/cpuinfo | grep flags | grep ' lm ' | wc -l
5. 查看计算机名 “hostname”
6. 查看内存 “cat /proc/meminfo”、“free -m”
7. 查看硬盘 “df -h”
8. 统计目录 “du -m”
9. 实时信息 top
10. 查看进程 “ps -ux”、“ps -ef | grep pid”
11. 只允许root登录:在/etc目录中执行“touch nologin”,删除产生的nologin文件即可恢复用户
12. 查询一个包是否被安装 “rpm -q xxx”、“rpm -qa | grep xxx”


https://wap.sciencenet.cn/blog-684520-544663.html

上一篇:我常用的一些学术链接
下一篇:学术文章的引言不好写?
收藏 IP: 119.78.98.*| 热度|

2 金小伟 师应龙

该博文允许注册用户评论 请点击登录 评论 (4 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-3-29 07:58

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部