/*
* Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Functions specific to Sun OS Solaris platforms.
*
* Thanks to Justin Venus who originally wrote a consistent part of
* this in Cython which I later on translated in C.
*/
/* fix compilation issue on SunOS 5.10, see:
* https://github.com/giampaolo/psutil/issues/421
* https://github.com/giampaolo/psutil/issues/1077
*/
#define _STRUCTURED_PROC 1
#include <Python.h>
#if !defined(_LP64) && _FILE_OFFSET_BITS == 64
# undef _FILE_OFFSET_BITS
# undef _LARGEFILE64_SOURCE
#endif
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/proc.h>
#include <sys/swap.h>
#include <sys/sysinfo.h>
#include <sys/mntent.h> // for MNTTAB
#include <sys/mnttab.h>
#include <sys/procfs.h>
#include <sys/sockio.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <utmpx.h>
#include <kstat.h>
#include <sys/ioctl.h>
#include <sys/tihdr.h>
#include <stropts.h>
#include <inet/tcp.h>
#ifndef NEW_MIB_COMPLIANT
/*
* Solaris introduced NEW_MIB_COMPLIANT macro with Update 4.
* See https://github.com/giampaolo/psutil/issues/421
* Prior to Update 4, one has to include mib2 by hand.
*/
#include <inet/mib2.h>
#endif
#include <arpa/inet.h>
#include <net/if.h>
#include <math.h> // fabs()
#include "_psutil_common.h"
#include "_psutil_posix.h"
#include "arch/solaris/environ.h"
#define PSUTIL_TV2DOUBLE(t) (((t).tv_nsec * 0.000000001) + (t).tv_sec)
/*
* Read a file content and fills a C structure with it.
*/
static int
psutil_file_to_struct(char *path, void *fstruct, size_t size) {
int fd;
ssize_t nbytes;
fd = open(path, O_RDONLY);
if (fd == -1) {
PyErr_SetFromErrnoWithFilename(PyExc_OSError, path);
return 0;
}
nbytes = read(fd, fstruct, size);
if (nbytes == -1) {
close(fd);
PyErr_SetFromErrno(PyExc_OSError);
return 0;
}
if (nbytes != (ssize_t) size) {
close(fd);
PyErr_SetString(
PyExc_RuntimeError, "read() file structure size mismatch");
return 0;
}
close(fd);
return nbytes;
}
/*
* Return process ppid, rss, vms, ctime, nice, nthreads, status and tty
* as a Python tuple.
*/
static PyObject *
psutil_proc_basic_info(PyObject *self, PyObject *args) {
int pid;
char path[1000];
psinfo_t info;
const char *procfs_path;
if (! PyArg_ParseTuple(args, "is", &pid, &procfs_path))
return NULL;
sprintf(path, "%s/%i/psinfo", procfs_path, pid);
if (! psutil_file_to_struct(path, (void *)&info, sizeof(info)))
return NULL;
return Py_BuildValue(
"ikkdiiikiiii",
info.pr_ppid, // parent pid
info.pr_rssize, // rss
info.pr_size, // vms
PSUTIL_TV2DOUBLE(info.pr_start), // create time
info.pr_lwp.pr_nice, // nice
info.pr_nlwp, // no. of threads
info.pr_lwp.pr_state, // status code
info.pr_ttydev, // tty nr
(int)info.pr_uid, // real user id
(int)info.pr_euid, // effective user id
(int)info.pr_gid, // real group id
(int)info.pr_egid // effective group id
);
}
/*
* Join array of C strings to C string with delimiter dm.
* Omit empty records.
*/
static int
cstrings_array_to_string(char **joined, char ** array, size_t count, char dm) {
size_t i;
size_t total_length = 0;
size_t item_length = 0;
char *result = NULL;
char *last = NULL;
if (!array || !joined)
return 0;
for (i=0; i<count; i++) {
if (!array[i])
continue;
item_length = strlen(array[i]) + 1;
total_length += item_length;
}
if (!total_length) {
return 0;
}
result = malloc(total_length);
if (!result) {
PyErr_NoMemory();
return -1;
}
result[0] = '\0';
last = result;
for (i=0; i<count; i++) {
if (!array[i])
continue;
item_length = strlen(array[i]);
memcpy(last, array[i], item_length);
last[item_length] = dm;
last += item_length + 1;
}
result[total_length-1] = '\0';
*joined = result;
return total_length;
}
/*
* Return process name and args as a Python tuple.
*/
static PyObject *
psutil_proc_name_and_args(PyObject *self, PyObject *args) {
int pid;
char path[1000];
psinfo_t info;
size_t argc;
int joined;
char **argv;
char *argv_plain;
const char *procfs_path;
PyObject *py_name = NULL;
PyObject *py_args = NULL;
PyObject *py_retlist = NULL;
if (! PyArg_ParseTuple(args, "is", &pid, &procfs_path))
return NULL;
sprintf(path, "%s/%i/psinfo", procfs_path, pid);
if (! psutil_file_to_struct(path, (void *)&info, sizeof(info)))
return NULL;
py_name = PyUnicode_DecodeFSDefault(info.pr_fname);
if (!py_name)
goto error;
/* SunOS truncates arguments to length PRARGSZ, very likely args are truncated.
* The only way to retrieve full command line is to parse process memory */
if (info.pr_argc && strlen(info.pr_psargs) == PRARGSZ-1) {
argv = psutil_read_raw_args(info, procfs_path, &argc);
if (argv) {
joined = cstrings_array_to_string(&argv_plain, argv, argc, ' ');
if (joined > 0) {
py_args = PyUnicode_DecodeFSDefault(argv_plain);
free(argv_plain);
} else if (joined < 0) {
goto error;
}
psutil_free_cstrings_array(argv, argc);
}
}
/* If we can't read process memory or can't decode the result
* then return args from /proc. */
if (!py_args) {
PyErr_Clear();
py_args = PyUnicode_DecodeFSDefault(info.pr_psargs);
}
/* Both methods has been failed. */
if (!py_args)
goto error;
py_retlist = Py_BuildValue("OO", py_name, py_args);
if (!py_retlist)
goto error;
Py_DECREF(py_name);
Py_DECREF(py_args);
return py_retlist;
error:
Py_XDECREF(py_name);
Py_XDECREF(py_args);
Py_XDECREF(py_retlist);
return NULL;
}
/*
* Return process environ block.
*/
static PyObject *
psutil_proc_environ(PyObject *self, PyObject *args) {
int pid;
char path[1000];
psinfo_t info;
const char *procfs_path;
char **env = NULL;
ssize_t env_count = -1;
char *dm;
int i = 0;
PyObject *py_envname = NULL;
PyObject *py_envval = NULL;
PyObject *py_retdict = PyDict_New();
if (! py_retdict)
return PyErr_NoMemory();
if (! PyArg_ParseTuple(args, "is", &pid, &procfs_path))
return NULL;
sprintf(path, "%s/%i/psinfo", procfs_path, pid);
if (! psutil_file_to_struct(path, (void *)&info, sizeof(info)))
goto error;
if (! info.pr_envp) {
AccessDenied("/proc/pid/psinfo struct not set");
goto error;
}
env = psutil_read_raw_env(info, procfs_path, &env_count);
if (! env && env_count != 0)
goto error;
for (i=0; i<env_count; i++) {
if (! env[i])
break;
dm = strchr(env[i], '=');
if (! dm)
continue;
*dm = '\0';
py_envname = PyUnicode_DecodeFSDefault(env[i]);
if (! py_envname)
goto error;
py_envval = PyUnicode_DecodeFSDefault(dm+1);
if (! py_envname)
goto error;
if (PyDict_SetItem(py_retdict, py_envname, py_envval) < 0)
goto error;
Py_CLEAR(py_envname);
Py_CLEAR(py_envval);
}
psutil_free_cstrings_array(env, env_count);
return py_retdict;
error:
if (env && env_count >= 0)
psutil_free_cstrings_array(env, env_count);
Py_XDECREF(py_envname);
Py_XDECREF(py_envval);
Py_XDECREF(py_retdict);
return NULL;
}
/
没有合适的资源?快使用搜索试试~ 我知道了~
在Python中用于进程和系统监控的跨平台库_Python_C_下载.zip
共226个文件
py:71个
c:56个
h:52个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 73 浏览量
2023-04-26
10:47:22
上传
评论
收藏 2.01MB ZIP 举报
温馨提示
在Python中用于进程和系统监控的跨平台库_Python_C_下载.zip
资源推荐
资源详情
资源评论
收起资源包目录
在Python中用于进程和系统监控的跨平台库_Python_C_下载.zip (226个子文件)
make.bat 7KB
make.bat 1KB
_psutil_sunos.c 49KB
proc.c 37KB
proc.c 34KB
_psutil_aix.c 29KB
_psutil_posix.c 27KB
proc_info.c 26KB
proc.c 19KB
proc.c 15KB
_psutil_linux.c 15KB
socks.c 14KB
net.c 13KB
services.c 13KB
disk.c 12KB
disk.c 12KB
_psutil_common.c 12KB
socks.c 12KB
cpu.c 11KB
proc_socks.c 11KB
_psutil_windows.c 10KB
proc.c 10KB
environ.c 10KB
sys_socks.c 10KB
proc.c 8KB
proc_handles.c 8KB
net_connections.c 8KB
_psutil_bsd.c 8KB
cpu.c 6KB
sys.c 6KB
cpu.c 5KB
proc_utils.c 5KB
disk.c 5KB
socks.c 5KB
_psutil_osx.c 5KB
mem.c 5KB
sys.c 4KB
ifaddrs.c 4KB
wmi.c 4KB
security.c 4KB
mem.c 3KB
sensors.c 3KB
mem.c 3KB
ifaddrs.c 3KB
mem.c 3KB
net.c 3KB
mem.c 3KB
net.c 3KB
cpu.c 3KB
cpu.c 3KB
disk.c 3KB
sys.c 2KB
sensors.c 2KB
common.c 2KB
disk.c 2KB
disk.c 2KB
cpu.c 2KB
sensors.c 895B
appveyor_run_with_compiler.cmd 3KB
CREDITS 12KB
custom.css 8KB
DEVNOTES 5KB
.flake8 1KB
.gitignore 149B
ntextapi.h 19KB
_psutil_common.h 6KB
net_kernel_structs.h 4KB
proc.h 2KB
proc.h 1KB
proc.h 1KB
proc_info.h 961B
proc.h 927B
common.h 894B
ifaddrs.h 767B
services.h 734B
proc.h 728B
cpu.h 584B
cpu.h 573B
ifaddrs.h 567B
proc.h 519B
proc_utils.h 517B
environ.h 511B
disk.h 466B
cpu.h 453B
disk.h 406B
net.h 399B
cpu.h 397B
mem.h 394B
security.h 365B
net_connections.h 356B
sensors.h 347B
cpu.h 338B
mem.h 335B
mem.h 335B
cpu.h 335B
socks.h 331B
mem.h 328B
mem.h 328B
sys.h 323B
sys.h 323B
共 226 条
- 1
- 2
- 3
资源评论
快撑死的鱼
- 粉丝: 1w+
- 资源: 9154
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Unity Easy Color Picker 2.2.1
- 基于Django和Hadoop集群进行的大数据分析平台
- openEuler-22.03-LTS-SP3-netinst-x86-64-dvd.iso
- AL-2023-4卷习题-文本文件
- openEuler-22.03-LTS-SP3-netinst-aarch64-dvd.iso
- openEuler-20.03-LTS-SP4-netinst-aarch64-dvd.iso
- 基于vue3.0的大数据分析系统,包含各种echarts和vue3.0新API
- 基于Java 实现WIFI探针的商业大数据分析技术(获得附近的人流量、入店量、驻留时长等信息 )
- Data$distriLecturer.class
- SECS移动解决方案 SECS如何实现扫码功能 SECS安卓APP SECS PDA应用 安卓版本SECS协议应用
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功