Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELF
- #include <linux/kernel.h>
- #include <linux/sched.h>
- #include <linux/module.h>
- asmlinkage int sys_printself(void)
- {
- struct task_struct *task;
- printk(KERN_INFO "My Process id: %d\n", current->pid);
- printk(KERN_INFO "My Name: %s\n", current->comm);
- printk(KERN_INFO "My parent processes until init :\n");
- for(task = current; task != &init_task; task = task->parent)
- {
- printk(KERN_INFO "Name: %s (PID: %d)\n",task->comm , task->pid);
- }
- return 0;
- }
- OTHER
- #include <linux/kernel.h>
- #include <linux/sched.h>
- #include <linux/module.h>
- asmlinkage int sys_printother(int pid)
- {
- struct task_struct *task;
- struct task_struct *temp_task;
- task = pid_task(find_vpid(pid), PIDTYPE_PID);
- if (task == NULL)
- printk(KERN_INFO "No process with PID %d\n", pid);
- else
- {
- printk(KERN_INFO "PID %d Name: %s\n", pid, task->comm);
- printk(KERN_INFO "PID %d parent processes until init :\n", pid);
- for(temp_task = task; temp_task != &init_task; temp_task = temp_task->parent)
- {
- printk(KERN_INFO "Name: %s (PID: %d)\n",temp_task->comm , temp_task->pid);
- }
- }
- return 0;
- }
- TEST
- #include <linux/unistd.h>
- #include <sys/syscall.h>
- #include <sys/types.h>
- #include <stdio.h>
- #define __NR_helloworld 337
- #define __NR_printself 338
- #define __NR_printother 339
- int main(int argc, char *argv[]) {
- syscall(__NR_helloworld);
- syscall(__NR_printself);
- int pidInput;
- printf("PID: ");
- scanf("%d", &pidInput);
- syscall(__NR_printother, pidInput);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement