Skip to content

Commit

Permalink
feat(procfs): update procfs (DragonOS-Community#831)
Browse files Browse the repository at this point in the history
为procfs增加是否是kthread的显示
增加返回进程已经占用的文件描述符数量
  • Loading branch information
donjuanplatinum authored May 28, 2024
1 parent 6cf1947 commit 3d4cd85
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
18 changes: 17 additions & 1 deletion kernel/src/filesystem/procfs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl ProcFSInode {
};
// 传入数据
let pdata: &mut Vec<u8> = &mut pdata.data;

// name
pdata.append(
&mut format!("Name:\t{}", pcb.basic().name())
.as_bytes()
Expand All @@ -174,24 +174,40 @@ impl ProcFSInode {
let priority = sched_info_guard.policy();
let vrtime = sched_info_guard.sched_entity.vruntime;

// State
pdata.append(&mut format!("\nState:\t{:?}", state).as_bytes().to_owned());

// Tgid
pdata.append(&mut format!("\nTgid:\t{}", pcb.tgid().into()).into());

// pid
pdata.append(
&mut format!("\nPid:\t{}", pcb.pid().into())
.as_bytes()
.to_owned(),
);

// ppid
pdata.append(
&mut format!("\nPpid:\t{}", pcb.basic().ppid().into())
.as_bytes()
.to_owned(),
);

// fdsize
pdata.append(&mut format!("\nFDSize:\t{}", pcb.fd_table().read().fd_open_count()).into());

// kthread
pdata.append(&mut format!("\nKthread:\t{}", pcb.is_kthread() as usize).into());

pdata.append(&mut format!("\ncpu_id:\t{}", cpu_id).as_bytes().to_owned());
pdata.append(&mut format!("\npriority:\t{:?}", priority).as_bytes().to_owned());
pdata.append(
&mut format!("\npreempt:\t{}", pcb.preempt_count())
.as_bytes()
.to_owned(),
);

pdata.append(&mut format!("\nvrtime:\t{}", vrtime).as_bytes().to_owned());

if let Some(user_vm) = pcb.basic().user_vm() {
Expand Down
11 changes: 11 additions & 0 deletions kernel/src/filesystem/vfs/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,17 @@ impl FileDescriptorVec {
return res;
}

/// 返回 `已经打开的` 文件描述符的数量
pub fn fd_open_count(&self) -> usize {
let mut size = 0;
for fd in &self.fds {
if fd.is_some() {
size += 1;
}
}
return size;
}

/// @brief 判断文件描述符序号是否合法
///
/// @return true 合法
Expand Down
11 changes: 11 additions & 0 deletions kernel/src/process/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,17 @@ impl ProcessControlBlock {
return Self::do_create_pcb(name, kstack, true);
}

/// # 函数的功能
///
/// 返回此函数是否是内核进程
///
/// # 返回值
///
/// 若进程是内核进程则返回true 否则返回false
pub fn is_kthread(&self) -> bool {
return matches!(self.flags(), &mut ProcessFlags::KTHREAD);
}

#[inline(never)]
fn do_create_pcb(name: String, kstack: KernelStack, is_idle: bool) -> Arc<Self> {
let (pid, ppid, cwd) = if is_idle {
Expand Down

0 comments on commit 3d4cd85

Please sign in to comment.