-
Notifications
You must be signed in to change notification settings - Fork 0
/
smunchR.c
47 lines (45 loc) · 1.62 KB
/
smunchR.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/pid.h>
#include <linux/types.h>
#include <linux/syscalls.h>
#include <linux/linkage.h>
SYSCALL_DEFINE2(smunch,int,pid,unsigned long,bit_pattern)
{
unsigned long flags;
struct task_struct *task;
rcu_read_lock();
task = pid_task(find_vpid(pid),PIDTYPE_PID);
rcu_read_unlock();
if(!task) return -1; // Process not present
if(!lock_task_sighand(task,&flags))
{
//Process refuses to give the lock. Either dead/dying
unlock_task_sighand(task,&flags);
return -1;
}
if(!thread_group_empty(task))
{
printk(KERN_ALERT "\nMULTI-Threaded Process, Exiting without processing");
ret=-1; goto return_path;
}
printk(KERN_ALERT "\nExit State:%XH,State=%XH\n",task->exit_state,task->state); //Info to user
if(task->state & TASK_UNINTERRUPTIBLE)
printk(KERN_ALERT "\nProcess is in Uniterruptible Wait-DeepSleep!!"); // Info to User
if(bit_pattern & (1UL<<(SIGKILL-1)) && (task->exit_state & EXIT_ZOMBIE))
{
printk(KERN_ALERT "\nSIGKILL present while Process is Zombie, releasing task!!");
unlock_task_sighand(task,&flags);
release_task(task); // detach_pid is called from release_task()
return 0;
}
/* If !SIGKILL || (ordinary process) || DeepSleep, sending all signals. It is Users responsility to note that signals will get handled from 1-64 order*/
printk(KERN_ALERT "!SIGKILL || (ordinary process) || DeepSleep, sending all signals!");
task->signal->shared_pending.signal.sig[0] = bit_pattern;
set_tsk_thread_flag(task,TIF_SIGPENDING);
signal_wake_up(task,1);
ret=0;
return_path:
unlock_task_sighand(task,&flags);
return ret;
}