美文网首页
ctrl+z, ctrl+c

ctrl+z, ctrl+c

作者: ThomasYoungK | 来源:发表于2018-08-14 08:53 被阅读11次

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

相关文章

网友评论

      本文标题:ctrl+z, ctrl+c

      本文链接:https://www.haomeiwen.com/subject/ufkmbftx.html