0

I tried to create a function ,in my module, that every time , when the system call sys_exit is called. So it will print the pid of the process that the user tried to stop (by press ctr+C, ctr+Z or something else).

asmlinkage long our_sys_exit(struct pt_regs *t)
{
printk("pid is %d \n",current->pid);
return older_sys_exit(t);
}

  

But I could not do it .

0andriy
  • 4,183
  • 1
  • 24
  • 37
  • Yes, because you have to override the system call table and wrap the one you need by your custom function. And I don't believe you may do it in module without special tricks that require kernel recompilation. Anyway, there are plenty of similar questions on SO and over the internet. – 0andriy Jul 08 '21 at 13:44
  • And why `python-3.x` tag is here?! – 0andriy Jul 08 '21 at 13:45
  • There are ways to intercept syscalls in the kernel using only a module, but in this case it is easier to change the signal handler of the shell to print out your message since you only care about SIGINT and SIGTSTP. I don't know if any shell has such functionality without recompiling, but which shell are you using? – Sagar Jul 22 '21 at 04:54

0 Answers0