上次使用shell script 的心得是,shell script 存取檔案還有關於字串處理沒有python方便,所以這次查詢 process 開檔數量就改用python 來實作。
上次的shell script:
Command-line translator using Google Translate
https://stackoverflow.max-everyday.com/2017/07/command-line-translator-using-google-translate/
#!/usr/bin/env python import subprocess child = subprocess.Popen(["ps -ef | grep server.py | grep -v grep | awk '{print $2}'"], stdout=subprocess.PIPE, shell=True) pid = child.communicate()[0] pid = pid.replace("\n","") print "pid:",pid cmd = "ls -l /proc/%s/fd | wc -l" % (pid) print "cmd:", cmd child = subprocess.Popen([cmd], stdout=subprocess.PIPE, shell=True) fd = child.communicate()[0] fd = fd.replace("\n","") print "fd:",fd