sys_getpgid.rs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. use crate::arch::interrupt::TrapFrame;
  2. use crate::arch::syscall::nr::SYS_GETPGID;
  3. use crate::process::Pid;
  4. use crate::process::ProcessManager;
  5. use crate::syscall::table::FormattedSyscallParam;
  6. use crate::syscall::table::Syscall;
  7. use alloc::vec::Vec;
  8. use system_error::SystemError;
  9. pub struct SysGetPgid;
  10. impl SysGetPgid {
  11. fn pid(args: &[usize]) -> Pid {
  12. Pid::new(args[0])
  13. }
  14. }
  15. impl Syscall for SysGetPgid {
  16. fn num_args(&self) -> usize {
  17. 1
  18. }
  19. /// # 函数的功能
  20. /// 获取指定进程的pgid
  21. ///
  22. /// ## 参数
  23. /// - pid: 指定一个进程号
  24. ///
  25. /// ## 返回值
  26. /// - 成功,指定进程的进程组id
  27. /// - 错误,不存在该进程
  28. fn handle(&self, args: &[usize], _frame: &mut TrapFrame) -> Result<usize, SystemError> {
  29. let pid = Self::pid(args);
  30. if pid == Pid(0) {
  31. let current_pcb = ProcessManager::current_pcb();
  32. return Ok(current_pcb.pgid().into());
  33. }
  34. let target_proc = ProcessManager::find(pid).ok_or(SystemError::ESRCH)?;
  35. return Ok(target_proc.pgid().into());
  36. }
  37. fn entry_format(&self, args: &[usize]) -> Vec<FormattedSyscallParam> {
  38. vec![FormattedSyscallParam::new(
  39. "pid",
  40. format!("{:#x}", Self::pid(args).0),
  41. )]
  42. }
  43. }
  44. syscall_table_macros::declare_syscall!(SYS_GETPGID, SysGetPgid);