SHARE
TWEET

cs45p1c

a guest Feb 14th, 2020 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELF
  2. #include <linux/kernel.h>
  3. #include <linux/sched.h>
  4. #include <linux/module.h>
  5.  
  6. asmlinkage int sys_printself(void)
  7. {
  8.   struct task_struct *task;
  9.  
  10.   printk(KERN_INFO "My Process id: %d\n", current->pid);
  11.   printk(KERN_INFO "My Name: %s\n", current->comm);
  12.   printk(KERN_INFO "My parent processes until init :\n");
  13.   for(task = current; task != &init_task; task = task->parent)
  14.   {
  15.     printk(KERN_INFO "Name: %s (PID: %d)\n",task->comm , task->pid);
  16.   }
  17.  
  18.   return 0;
  19. }
  20.  
  21. OTHER
  22.  
  23. #include <linux/kernel.h>
  24. #include <linux/sched.h>
  25. #include <linux/module.h>
  26.  
  27. asmlinkage int sys_printother(int pid)
  28. {
  29.   struct task_struct *task;
  30.   struct task_struct *temp_task;
  31.  
  32.   task = pid_task(find_vpid(pid), PIDTYPE_PID);
  33.  
  34.   if (task == NULL)
  35.     printk(KERN_INFO "No process with PID %d\n", pid);
  36.   else
  37.   {
  38.     printk(KERN_INFO "PID %d Name: %s\n", pid, task->comm);
  39.     printk(KERN_INFO "PID %d parent processes until init :\n", pid);
  40.     for(temp_task = task; temp_task != &init_task; temp_task = temp_task->parent)
  41.     {
  42.       printk(KERN_INFO "Name: %s (PID: %d)\n",temp_task->comm , temp_task->pid);
  43.     }
  44.   }
  45.  
  46.   return 0;
  47. }
  48.  
  49. TEST
  50. #include <linux/unistd.h>
  51. #include <sys/syscall.h>
  52. #include <sys/types.h>
  53. #include <stdio.h>
  54.  
  55. #define __NR_helloworld 337
  56. #define __NR_printself  338
  57. #define __NR_printother 339
  58.  
  59. int main(int argc, char *argv[]) {
  60.         syscall(__NR_helloworld);
  61.         syscall(__NR_printself);
  62.  
  63.         int pidInput;
  64.         printf("PID: ");
  65.         scanf("%d", &pidInput);
  66.  
  67.  
  68.         syscall(__NR_printother, pidInput);
  69.         return 0;
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top