49static void FillFdInfo(
struct SeqBuf *seqBuf,
struct filelist *fileList,
unsigned int pid,
bool hasPrivilege)
54 struct file *filp = NULL;
57 if ((fdt == NULL) || (fdt->
proc_fds == NULL)) {
63 for (fd = MIN_START_FD; fd < fdt->
max_fds; fd++) {
66 if (sysFd < CONFIG_NFILE_DESCRIPTORS) {
67 filp = &fileList->fl_files[sysFd];
69 }
else if (sysFd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS)) {
71 }
else if (sysFd < (FD_SETSIZE + CONFIG_NTIME_DESCRIPTORS)) {
73 }
else if (sysFd < (MQUEUE_FD_OFFSET + CONFIG_NQUEUE_DESCRIPTORS)) {
75 }
else if (sysFd < (EPOLL_FD_OFFSET + CONFIG_EPOLL_DESCRIPTORS)) {
96 unsigned int pidMaxNum;
97 unsigned int *pidList = NULL;
102 pidList = (
unsigned int *)
malloc(pidMaxNum *
sizeof(
unsigned int));
103 if (pidList == NULL) {
108 (
void)
LosBufPrintf(seqBuf,
"%s\t%s\t%6s %s\t%s\n",
"Pid",
"Fd",
"SysFd",
"<ref>",
"Name");
111 pidList = (
unsigned int *)
malloc(pidNum *
sizeof(
unsigned int));
112 if (pidList == NULL) {
116 hasPrivilege =
false;
120 struct filelist *fileList = &tg_filelist;
123 for (
int i = 0; i < pidNum; i++) {
124 FillFdInfo(seqBuf, fileList, pidList[i], hasPrivilege);
140 PRINT_ERR(
"creat /proc/fd error.\n");
BOOL IsCapPermit(UINT32 capIndex)
static const struct ProcFileOperations FD_PROC_FOPS
static void FillFdInfo(struct SeqBuf *seqBuf, struct filelist *fileList, unsigned int pid, bool hasPrivilege)
static int FdProcFill(struct SeqBuf *seqBuf, void *v)
LITE_OS_SEC_TEXT INT32 LOS_GetUsedPIDList(UINT32 *pidList, INT32 pidMaxNum)
LOS_GetUsedPIDList 获取使用中的进程列表
LITE_OS_SEC_TEXT struct fd_table_s * LOS_GetFdTable(UINT32 pid)
LITE_OS_SEC_TEXT UINT32 LOS_GetSystemProcessMaximum(VOID)
获取系统支持的最大进程数目
LITE_OS_SEC_TEXT UINT32 LOS_GetCurrProcessID(VOID)
获取当前进程的进程ID
int LosBufPrintf(struct SeqBuf *seqBuf, const char *fmt,...)
支持可变参数 写 buf
void * malloc(size_t size)
动态分配内存块大小
void free(void *ptr)
释放ptr所指向的内存空间
struct ProcDirEntry * CreateProcEntry(const char *name, mode_t mode, struct ProcDirEntry *parent)
create a proc node
int sem_post(sem_t *sem)
增加信号量计数
int sem_wait(sem_t *sem)
获取信号量
proc 目录/文件项, @notethinking 直接叫 ProcEntry不香吗 ? 操作 /proc的 真正结构体
const struct ProcFileOperations * procFileOps
驱动程序,每个 /proc 下目录的驱动程序都不一样
真正最后能操作pro file的接口,proc本质是个内存文件系统, vfs - > ProcFileOperations
int(* read)(struct SeqBuf *m, void *v)
struct file_table_s * ft_fds
unsigned int max_fds
进程的文件描述符最多有256个
fd_set * proc_fds
进程fd管理位,用bitmap管理FD使用情况,默认打开了 0,1,2 (stdin,stdout,stderr)
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void