[c] a

Viewer

  1. #include <linux/kernel.h>
  2. #include <linux/sched.h>
  3. #include <linux/syscalls.h>
  4. #include <linux/errno.h>
  5. #include <linux/string.h>
  6. struct proc_info {
  7.     pid_t pid;
  8.         char name[16];
  9. };
  10. struct procinfos {
  11.         long studentID;
  12.         struct proc_info proc;
  13.         struct proc_info parent_proc;
  14.         struct proc_info oldest_child_proc;
  15. };
  16. asmlinkage long sys_get_proc_info(pid_t pid, struct procinfos * info) {
  17.     info->studentID = 1810582;
  18.     if (pid == -1) {
  19.         pid = current->pid;
  20.     }
  21.     struct task_struct *process;
  22.     struct task_struct *child_process;
  23.     int i = 0;
  24.     int a = 0;
  25.     if (== 0) {
  26.         a = 1;
  27.     }
  28.     else a = 2;
  29.     for_each_process(process) {
  30.         if (pid == process->pid) {
  31.             info->proc.pid = process->pid;
  32.             strcpy(info->proc.name, process->comm);
  33.             if (process->real_parent) {
  34.                 info->parent_proc.pid = process->real_parent->pid;
  35.                 strcpy(info->parent_proc.name, process->real_parent->comm);
  36.             }
  37.             else if (process->real_parent == NULL) {
  38.                 info->parent_proc.pid = 0;
  39.                 strcpy(info->parent_proc.name, "Miss parent\n");
  40.             }
  41.             child_process = list_first_entry_or_null(&process->children, struct task_struct, sibling);
  42.             if (child_process) {
  43.                 info->oldest_child_proc.pid = child_process->pid;
  44.                 strcpy(info->oldest_child_proc.name, child_process->comm);
  45.             }
  46.             else if (child_process == NULL) {
  47.                 info->oldest_child_proc.pid = 0;
  48.                 strcpy(info->oldest_child_proc.name, "Miss child\n");
  49.             }
  50.             return 0;
  51.         }
  52.     }
  53.     return -1;
  54. }
  55. SYSCALL_DEFINE2(sys_get_proc_info, pid_t, pid, struct procinfos*, info) {
  56.         return sys_get_proc_info(pid, info);
  57. }

Editor

You can edit this paste and save as new: