@name 获取进程连接信息 @author hwliang<2021-08-09> @param pid @return dict
(self,pid)
| 1811 | |
| 1812 | |
| 1813 | def get_connects(self,pid): |
| 1814 | ''' |
| 1815 | @name 获取进程连接信息 |
| 1816 | @author hwliang<2021-08-09> |
| 1817 | @param pid<int> |
| 1818 | @return dict |
| 1819 | ''' |
| 1820 | connects = 0 |
| 1821 | try: |
| 1822 | if pid == 1: return connects |
| 1823 | tp = '/proc/' + str(pid) + '/fd/' |
| 1824 | if not os.path.exists(tp): return connects |
| 1825 | for d in os.listdir(tp): |
| 1826 | fname = tp + d |
| 1827 | if os.path.islink(fname): |
| 1828 | l = os.readlink(fname) |
| 1829 | if l.find('socket:') != -1: connects += 1 |
| 1830 | except:pass |
| 1831 | return connects |
| 1832 | |
| 1833 | |
| 1834 | def format_connections(self,connects): |
no test coverage detected