1.后台运行nohup
nohup python -u my.py >> my.log 2>&1 &
-u 参数,使得python不启用缓冲。
my.py 自己的代码
my.log 输出的文件
2.查看进程
ps -ef
ps -aux
3.杀死进程
正常杀死进程(推荐)
kill -15 进程号
强制杀死进程
kill -9 进程号
例子
nohup python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wrn][250] -i 3 -o -a >> myFeat.log 2>&1 &
[1] 17448
ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 10:13 ? 00:00:00 bash /init/boot/boot.sh
root 711 1 0 10:13 ? 00:00:21 /bin/supervisord -c /init/supervisor/supervisor.ini
root 725 711 0 10:13 ? 00:00:00 /usr/sbin/sshd -D
root 732 711 0 10:13 ? 00:00:00 /root/miniconda3/bin/python /root/miniconda3/bin/jupyter-lab --allow-root --config=/init/jupyter/jupyter_con
root 733 711 0 10:13 ? 00:00:02 autopanel serve --work-dir=/root/autodl-tmp --cache-dir=/root/autodl-tmp
root 734 711 0 10:13 ? 00:00:02 proxy -c /init/proxy/proxy.ini
root 963 725 0 10:14 ? 00:00:00 sshd: root@pts/1
root 974 725 0 10:14 ? 00:00:00 sshd: root@notty
root 976 963 0 10:14 pts/1 00:00:00 -bash
root 1023 974 0 10:14 ? 00:00:00 /usr/lib/openssh/sftp-server
root 17448 976 99 10:50 pts/1 00:03:52 python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wr
root 17549 17448 30 10:51 pts/1 00:00:59 python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wr
root 17550 17448 30 10:51 pts/1 00:00:59 python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wr
root 17551 17448 29 10:51 pts/1 00:00:59 python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wr
root 17552 17448 30 10:51 pts/1 00:00:59 python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wr
root 17557 17448 30 10:51 pts/1 00:01:00 python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wr
root 17558 17448 30 10:51 pts/1 00:01:00 python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wr
root 17559 17448 30 10:51 pts/1 00:00:59 python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wr
root 17560 17448 30 10:51 pts/1 00:01:00 python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wr
root 17569 17448 29 10:51 pts/1 00:00:59 python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wr
root 17570 17448 29 10:51 pts/1 00:00:58 python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wr
root 17571 17448 29 10:51 pts/1 00:00:59 python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wr
root 17572 17448 29 10:51 pts/1 00:00:58 python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wr
root 21450 976 0 10:54 pts/1 00:00:00 ps -ef
kill -9 17448
ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 10:13 ? 00:00:00 bash /init/boot/boot.sh
root 711 1 0 10:13 ? 00:00:25 /bin/supervisord -c /init/supervisor/supervisor.ini
root 725 711 0 10:13 ? 00:00:00 /usr/sbin/sshd -D
root 732 711 0 10:13 ? 00:00:00 /root/miniconda3/bin/python /root/miniconda3/bin/jupyter-lab --allow-root --config=/init/jupyter/jupyter_con
root 733 711 0 10:13 ? 00:00:02 autopanel serve --work-dir=/root/autodl-tmp --cache-dir=/root/autodl-tmp
root 734 711 0 10:13 ? 00:00:02 proxy -c /init/proxy/proxy.ini
root 963 725 0 10:14 ? 00:00:00 sshd: root@pts/1
root 974 725 0 10:14 ? 00:00:00 sshd: root@notty
root 976 963 0 10:14 pts/1 00:00:00 -bash
root 1023 974 0 10:14 ? 00:00:00 /usr/lib/openssh/sftp-server
root 29609 976 0 11:02 pts/1 00:00:00 ps -ef
[1]+ Killed nohup python3 -u train/featmatch.py -cf config/cifar10/[cifar10][test][wrn][250].json -d 0 1 -n [cifar10][test][wrn][250] -i 3 -o -a >> myFeat.log 2>&1