scrapyer@spider0:~$ nohup python3 -u test1.py > log.log 2>&1 &
[1] 720875
scrapyer@spider0:~$ ps -ef |grep test1.py
scrapyer 720875 720633 0 17:43 pts/1 00:00:00 python3 -u test1.py
scrapyer 720889 720633 0 17:43 pts/1 00:00:00 grep test1.py
scrapyer@spider0:~$ ps -ef |grep test1.py |cut -c 9-15
72087
72096
scrapyer@spider0:~$ ps -ef |grep test1.py |cut -c 9-16
720875
720986
scrapyer@spider0:~$ cat log.log
nohup: ignoring input
2021-05-17 17:43:18
2021-05-17 17:43:23
2021-05-17 17:43:28
2021-05-17 17:43:33
2021-05-17 17:43:38
2021-05-17 17:43:43
2021-05-17 17:43:48
2021-05-17 17:43:53
2021-05-17 17:43:58
2021-05-17 17:44:03
scrapyer@spider0:~$ ps -ef |grep test1.py |grep -w grep|cut -c 9-16
721115
scrapyer@spider0:~$ ps -ef |grep tesd1
scrapyer 721155 720633 0 17:44 pts/1 00:00:00 grep tesd1
scrapyer@spider0:~$ ps -ef |grep test1
scrapyer 720875 720633 0 17:43 pts/1 00:00:00 python3 -u test1.py
scrapyer 721180 720633 0 17:45 pts/1 00:00:00 grep test1
scrapyer@spider0:~$ ps -ef |grep test1.py |grep -w grep
scrapyer 721217 720633 0 17:45 pts/1 00:00:00 grep test1.py
scrapyer@spider0:~$ ps -ef |grep test1.py |grep -v grep
scrapyer 720875 720633 0 17:43 pts/1 00:00:00 python3 -u test1.py
scrapyer@spider0:~$ ps -ef |grep test1.py |grep -v grep |cut -c 9-16
720875
scrapyer@spider0:~$ ps -ef |grep test1.py |grep -v grep |cut -c 9-16
720875
scrapyer@spider0:~$ ps -ef |grep test1.py |grep -v grep |cut -c 9-16 |xargs kill -stop[1]+ Stopped nohup python3 -u test1.py > log.log 2>&1
scrapyer@spider0:~$ ps -ef |grep test1.py |grep -v grep |cut -c 9-16 |xargs kill -start
kill: (720875): Invalid argument
scrapyer@spider0:~$ cat log.log
nohup: ignoring input
2021-05-17 17:43:18
2021-05-17 17:43:23
2021-05-17 17:43:28
2021-05-17 17:43:33
2021-05-17 17:43:38
2021-05-17 17:43:43
2021-05-17 17:43:48
2021-05-17 17:43:53
2021-05-17 17:43:58
2021-05-17 17:44:03
2021-05-17 17:44:08
2021-05-17 17:44:13
2021-05-17 17:44:18
2021-05-17 17:44:23
2021-05-17 17:44:28
2021-05-17 17:44:33
2021-05-17 17:44:38
2021-05-17 17:44:43
2021-05-17 17:44:48
2021-05-17 17:44:53
2021-05-17 17:44:58
2021-05-17 17:45:03
2021-05-17 17:45:08
2021-05-17 17:45:13
2021-05-17 17:45:18
2021-05-17 17:45:23
2021-05-17 17:45:28
2021-05-17 17:45:33
2021-05-17 17:45:38
2021-05-17 17:45:43
2021-05-17 17:45:48
2021-05-17 17:45:53
2021-05-17 17:45:58
2021-05-17 17:46:03
2021-05-17 17:46:08
2021-05-17 17:46:13
2021-05-17 17:46:18
2021-05-17 17:46:23
2021-05-17 17:46:28
scrapyer@spider0:~$ tail -n 10 log.log
2021-05-17 17:45:43
2021-05-17 17:45:48
2021-05-17 17:45:53
2021-05-17 17:45:58
2021-05-17 17:46:03
2021-05-17 17:46:08
2021-05-17 17:46:13
2021-05-17 17:46:18
2021-05-17 17:46:23
2021-05-17 17:46:28
scrapyer@spider0:~$ tail -n 10 log.log
2021-05-17 17:45:43
2021-05-17 17:45:48
2021-05-17 17:45:53
2021-05-17 17:45:58
2021-05-17 17:46:03
2021-05-17 17:46:08
2021-05-17 17:46:13
2021-05-17 17:46:18
2021-05-17 17:46:23
2021-05-17 17:46:28
scrapyer@spider0:~$ ps -ef |grep test1.py |grep -v grep |cut -c 9-16 |xargs kill -reload
kill: invalid argument rUsage:
kill [options] <pid> [...]Options:
<pid> [...] send signal to every <pid> listed
-<signal>, -s, --signal <signal>
specify the <signal> to be sent
-l, --list=[<signal>] list all signal names, or convert one to a name
-L, --table list all signal names in a nice table-h, --help display this help and exit
-V, --version output version information and exitFor more details see kill(1).
scrapyer@spider0:~$ ps -ef |grep test1.py |grep -v grep |cut -c 9-16 |xargs kill -cont
scrapyer@spider0:~$ tail -n 10 log.log
2021-05-17 17:45:48
2021-05-17 17:45:53
2021-05-17 17:45:58
2021-05-17 17:46:03
2021-05-17 17:46:08
2021-05-17 17:46:13
2021-05-17 17:46:18
2021-05-17 17:46:23
2021-05-17 17:46:28
2021-05-17 17:52:03
scrapyer@spider0:~$ tail -n 10 log.log
2021-05-17 17:45:48
2021-05-17 17:45:53
2021-05-17 17:45:58
2021-05-17 17:46:03
2021-05-17 17:46:08
2021-05-17 17:46:13
2021-05-17 17:46:18
2021-05-17 17:46:23
2021-05-17 17:46:28
2021-05-17 17:52:03
scrapyer@spider0:~$ tail -n 10 log.log
2021-05-17 17:45:53
2021-05-17 17:45:58
2021-05-17 17:46:03
2021-05-17 17:46:08
2021-05-17 17:46:13
2021-05-17 17:46:18
2021-05-17 17:46:23
2021-05-17 17:46:28
2021-05-17 17:52:03
2021-05-17 17:52:08
scrapyer@spider0:~$ ps -ef |grep test1.py |grep -v grep |cut -c 9-16 |xargs kill -stop[1]+ Stopped nohup python3 -u test1.py > log.log 2>&1
scrapyer@spider0:~$ vim ps_stop.sh
scrapyer@spider0:~$ bash ps_stop.shscrapyer@spider0:~$ bash ps_stop.sh 111
111
scrapyer@spider0:~$ vim ps_stop.sh
scrapyer@spider0:~$ bash ps_stop.sh test1.py
进程名称:test1.py
scrapyer 720875 720633 0 17:43 pts/1 00:00:00 python3 -u test1.py
scrapyer 723483 720633 0 17:59 pts/1 00:00:00 bash ps_stop.sh test1.py
是否暂停进程:test1.py(y/n)n
取消暂停进程!
scrapyer@spider0:~$ bash ps_stop.sh test1.py
进程名称:test1.py
scrapyer 720875 720633 0 17:43 pts/1 00:00:00 python3 -u test1.py
scrapyer 723569 720633 0 17:59 pts/1 00:00:00 bash ps_stop.sh test1.py
是否暂停进程:test1.py(y/n)yes[2]+ Stopped bash ps_stop.sh test1.py
scrapyer@spider0:~$ chmod +x ps_stop.sh
scrapyer@spider0:~$ ./ps_stop.sh test1
进程名称:test1
scrapyer 720875 720633 0 17:43 pts/1 00:00:00 python3 -u test1.py
scrapyer 723569 720633 0 17:59 pts/1 00:00:00 bash ps_stop.sh test1.py
scrapyer 723723 720633 0 18:00 pts/1 00:00:00 /bin/bash ./ps_stop.sh test1
是否暂停进程:test1(y/n)n
取消暂停进程!
#!/bin/bash
psname=$1
echo "进程名称:$psname"
ps -ef |grep $psname |grep -v grep
read -p "是否暂停进程:$psname(y/n)" choose
if [ "$choose" = "y" ] || [ "$choose" = "yes" ];
then
ps -ef |grep $psname |grep -v grep |cut -c 9-16 |xargs kill -stop
else
echo "取消暂停进程!"
fi
#encoding=utf-8
import time
while 1:
print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime()))
time.sleep(5)