5 #include <linux/sched.h>
6 #include <linux/kernel.h>
8 #include <asm/segment.h>
11 int sys_close(int fd
);
13 void release(struct task_struct
* p
)
19 for (i
=1 ; i
<NR_TASKS
; i
++)
26 panic("trying to release non-existent task");
29 static inline void send_sig(long sig
,struct task_struct
* p
,int priv
)
31 if (!p
|| sig
<1 || sig
>32)
34 current
->uid
==p
->uid
||
35 current
->euid
==p
->uid
||
36 current
->uid
==p
->euid
||
37 current
->euid
==p
->euid
)
38 p
->signal
|= (1<<(sig
-1));
41 void do_kill(long pid
,long sig
,int priv
)
43 struct task_struct
**p
= NR_TASKS
+ task
;
45 if (!pid
) while (--p
> &FIRST_TASK
) {
46 if (*p
&& (*p
)->pgrp
== current
->pid
)
47 send_sig(sig
,*p
,priv
);
48 } else if (pid
>0) while (--p
> &FIRST_TASK
) {
49 if (*p
&& (*p
)->pid
== pid
)
50 send_sig(sig
,*p
,priv
);
51 } else if (pid
== -1) while (--p
> &FIRST_TASK
)
52 send_sig(sig
,*p
,priv
);
53 else while (--p
> &FIRST_TASK
)
54 if (*p
&& (*p
)->pgrp
== -pid
)
55 send_sig(sig
,*p
,priv
);
58 int sys_kill(int pid
,int sig
)
60 do_kill(pid
,sig
,!(current
->uid
|| current
->euid
));
64 int do_exit(long code
)
68 free_page_tables(get_base(current
->ldt
[1]),get_limit(0x0f));
69 free_page_tables(get_base(current
->ldt
[2]),get_limit(0x17));
70 for (i
=0 ; i
<NR_TASKS
; i
++)
71 if (task
[i
] && task
[i
]->father
== current
->pid
)
73 for (i
=0 ; i
<NR_OPEN
; i
++)
80 if (current
->leader
&& current
->tty
>= 0)
81 tty_table
[current
->tty
].pgrp
= 0;
82 if (last_task_used_math
== current
)
83 last_task_used_math
= NULL
;
84 if (current
->father
) {
85 current
->state
= TASK_ZOMBIE
;
86 do_kill(current
->father
,SIGCHLD
,1);
87 current
->exit_code
= code
;
91 return (-1); /* just to suppress warnings */
94 int sys_exit(int error_code
)
96 return do_exit((error_code
&0xff)<<8);
99 int sys_waitpid(pid_t pid
,int * stat_addr
, int options
)
102 struct task_struct
** p
;
104 verify_area(stat_addr
,4);
106 for(p
= &LAST_TASK
; p
> &FIRST_TASK
; --p
)
107 if (*p
&& *p
!= current
&&
108 (pid
==-1 || (*p
)->pid
==pid
||
109 (pid
==0 && (*p
)->pgrp
==current
->pgrp
) ||
110 (pid
<0 && (*p
)->pgrp
==-pid
)))
111 if ((*p
)->father
== current
->pid
) {
113 if ((*p
)->state
==TASK_ZOMBIE
) {
114 put_fs_long((*p
)->exit_code
,
115 (unsigned long *) stat_addr
);
116 current
->cutime
+= (*p
)->utime
;
117 current
->cstime
+= (*p
)->stime
;
124 if (options
& WNOHANG
)
127 if (!(current
->signal
&= ~(1<<(SIGCHLD
-1))))