ctrl+z, ctrl+c

ctrl+c:终端进程

ctrl+z:挂起进程
jobs:查看挂起的进程, 比如下图2个进程都被挂起了

[1]  - suspended  python compare_thread_sequence.py
[2]  + suspended  python3 compare_thread_sequence.py

fg %N: 让挂起的进程在前台继续运行,N是jobs前面显示的编号
bg %N: 让挂起的进程在后台继续运行

举个例子:
compare_thread_sequence.py是个python脚本

"""python3与python2有不同的结果,python2sequence几乎是双线程速度的2倍。
python3两者速度就差不多了,但是python3做了个折中,sequence速度比python2慢,多线程比python2快"""

from threading import Thread
import time

def count(n):
    while n > 0:
        n -= 1

start = time.time()
count(100000000)
count(100000000)
end = time.time()
print(end-start)

start = time.time()
t1 = Thread(target=count,args=(100000000,))
t1.start()
t2 = Thread(target=count,args=(100000000,))
t2.start()
t1.join()
t2.join()
end = time.time()
print(end-start)
➜  python2_test python compare_thread_sequence.py
^Z
[1]  + 19277 suspended  python compare_thread_sequence.py
➜  python2_test python3 compare_thread_sequence.py
^Z
[2]  + 19287 suspended  python3 compare_thread_sequence.py
➜  python2_test jobs
[1]  - suspended  python compare_thread_sequence.py
[2]  + suspended  python3 compare_thread_sequence.py
➜  python2_test bg %1
[1]  - 19277 continued  python compare_thread_sequence.py
➜  python2_test jobs
[1]  - running    python compare_thread_sequence.py
[2]  + suspended  python3 compare_thread_sequence.py
➜  python2_test 34.6158938408
16.4271929264

[1]  - 19277 done       python compare_thread_sequence.py
➜  python2_test jobs
[2]  + suspended  python3 compare_thread_sequence.py
➜  python2_test bg
[2]  + 19287 continued  python3 compare_thread_sequence.py
➜  python2_test jobs
[2]  + running    python3 compare_thread_sequence.py
➜  python2_test 61.20273995399475
13.181246995925903

[2]  + 19287 done       python3 compare_thread_sequence.py
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容