xref: /openbsd-src/sys/kern/kern_exit.c (revision 34b8a7e274ff61bb47b6015f5da6546d44d5c136)
1 /*	$OpenBSD: kern_exit.c,v 1.135 2014/02/12 05:47:36 guenther Exp $	*/
2 /*	$NetBSD: kern_exit.c,v 1.39 1996/04/22 01:38:25 christos Exp $	*/
3 
4 /*
5  * Copyright (c) 1982, 1986, 1989, 1991, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  * (c) UNIX System Laboratories, Inc.
8  * All or some portions of this file are derived from material licensed
9  * to the University of California by American Telephone and Telegraph
10  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
11  * the permission of UNIX System Laboratories, Inc.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *	@(#)kern_exit.c	8.7 (Berkeley) 2/12/94
38  */
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/ioctl.h>
43 #include <sys/proc.h>
44 #include <sys/tty.h>
45 #include <sys/time.h>
46 #include <sys/resource.h>
47 #include <sys/kernel.h>
48 #include <sys/buf.h>
49 #include <sys/wait.h>
50 #include <sys/file.h>
51 #include <sys/vnode.h>
52 #include <sys/syslog.h>
53 #include <sys/malloc.h>
54 #include <sys/resourcevar.h>
55 #include <sys/ptrace.h>
56 #include <sys/acct.h>
57 #include <sys/filedesc.h>
58 #include <sys/signalvar.h>
59 #include <sys/sched.h>
60 #include <sys/ktrace.h>
61 #include <sys/pool.h>
62 #include <sys/mutex.h>
63 #ifdef SYSVSEM
64 #include <sys/sem.h>
65 #endif
66 
67 #include "systrace.h"
68 #include <dev/systrace.h>
69 
70 #include <sys/mount.h>
71 #include <sys/syscallargs.h>
72 
73 
74 #include <uvm/uvm_extern.h>
75 
76 /*
77  * exit --
78  *	Death of process.
79  */
80 int
81 sys_exit(struct proc *p, void *v, register_t *retval)
82 {
83 	struct sys_exit_args /* {
84 		syscallarg(int) rval;
85 	} */ *uap = v;
86 
87 	exit1(p, W_EXITCODE(SCARG(uap, rval), 0), EXIT_NORMAL);
88 	/* NOTREACHED */
89 	return (0);
90 }
91 
92 int
93 sys___threxit(struct proc *p, void *v, register_t *retval)
94 {
95 	struct sys___threxit_args /* {
96 		syscallarg(pid_t *) notdead;
97 	} */ *uap = v;
98 
99 	if (SCARG(uap, notdead) != NULL) {
100 		pid_t zero = 0;
101 		if (copyout(&zero, SCARG(uap, notdead), sizeof(zero)))
102 			psignal(p, SIGSEGV);
103 	}
104 	exit1(p, 0, EXIT_THREAD);
105 
106 	return (0);
107 }
108 
109 /*
110  * Exit: deallocate address space and other resources, change proc state
111  * to zombie, and unlink proc from allproc and parent's lists.  Save exit
112  * status and rusage for wait().  Check for child processes and orphan them.
113  */
114 void
115 exit1(struct proc *p, int rv, int flags)
116 {
117 	struct process *pr, *qr, *nqr;
118 	struct rusage *rup;
119 	struct vnode *ovp;
120 
121 	if (p->p_pid == 1)
122 		panic("init died (signal %d, exit %d)",
123 		    WTERMSIG(rv), WEXITSTATUS(rv));
124 
125 	atomic_setbits_int(&p->p_flag, P_WEXIT);
126 
127 	pr = p->p_p;
128 
129 	/* single-threaded? */
130 	if (TAILQ_FIRST(&pr->ps_threads) == p &&
131 	    TAILQ_NEXT(p, p_thr_link) == NULL) {
132 		flags = EXIT_NORMAL;
133 	} else {
134 		/* nope, multi-threaded */
135 		if (flags == EXIT_NORMAL)
136 			single_thread_set(p, SINGLE_EXIT, 0);
137 		else if (flags == EXIT_THREAD)
138 			single_thread_check(p, 0);
139 	}
140 
141 	if (flags == EXIT_NORMAL) {
142 		atomic_setbits_int(&pr->ps_flags, PS_EXITING);
143 		pr->ps_mainproc->p_xstat = rv;
144 
145 		/*
146 		 * If parent is waiting for us to exit or exec, PS_PPWAIT
147 		 * is set; we wake up the parent early to avoid deadlock.
148 		 */
149 		if (pr->ps_flags & PS_PPWAIT) {
150 			atomic_clearbits_int(&pr->ps_flags, PS_PPWAIT);
151 			atomic_clearbits_int(&pr->ps_pptr->ps_flags,
152 			    PS_ISPWAIT);
153 			wakeup(pr->ps_pptr);
154 		}
155 	}
156 
157 	/* unlink ourselves from the active threads */
158 	TAILQ_REMOVE(&pr->ps_threads, p, p_thr_link);
159 	if ((p->p_flag & P_THREAD) == 0) {
160 		/* main thread gotta wait because it has the pid, et al */
161 		while (!TAILQ_EMPTY(&pr->ps_threads))
162 			tsleep(&pr->ps_threads, PUSER, "thrdeath", 0);
163 		if (pr->ps_flags & PS_PROFIL)
164 			stopprofclock(pr);
165 	} else if (TAILQ_EMPTY(&pr->ps_threads)) {
166 		wakeup(&pr->ps_threads);
167 	}
168 
169 	rup = pr->ps_ru;
170 	if (rup == NULL) {
171 		rup = pool_get(&rusage_pool, PR_WAITOK | PR_ZERO);
172 		if (pr->ps_ru == NULL) {
173 			pr->ps_ru = rup;
174 		} else {
175 			pool_put(&rusage_pool, rup);
176 			rup = pr->ps_ru;
177 		}
178 	}
179 	p->p_siglist = 0;
180 
181 	/*
182 	 * Close open files and release open-file table.
183 	 */
184 	fdfree(p);
185 
186 	if ((p->p_flag & P_THREAD) == 0) {
187 		timeout_del(&pr->ps_realit_to);
188 #ifdef SYSVSEM
189 		semexit(pr);
190 #endif
191 		if (SESS_LEADER(pr)) {
192 			struct session *sp = pr->ps_session;
193 
194 			if (sp->s_ttyvp) {
195 				/*
196 				 * Controlling process.
197 				 * Signal foreground pgrp,
198 				 * drain controlling terminal
199 				 * and revoke access to controlling terminal.
200 				 */
201 				if (sp->s_ttyp->t_session == sp) {
202 					if (sp->s_ttyp->t_pgrp)
203 						pgsignal(sp->s_ttyp->t_pgrp,
204 						    SIGHUP, 1);
205 					ttywait(sp->s_ttyp);
206 					/*
207 					 * The tty could have been revoked
208 					 * if we blocked.
209 					 */
210 					if (sp->s_ttyvp)
211 						VOP_REVOKE(sp->s_ttyvp,
212 						    REVOKEALL);
213 				}
214 				ovp = sp->s_ttyvp;
215 				sp->s_ttyvp = NULL;
216 				if (ovp)
217 					vrele(ovp);
218 				/*
219 				 * s_ttyp is not zero'd; we use this to
220 				 * indicate that the session once had a
221 				 * controlling terminal.  (for logging and
222 				 * informational purposes)
223 				 */
224 			}
225 			sp->s_leader = NULL;
226 		}
227 		fixjobc(pr, pr->ps_pgrp, 0);
228 
229 #ifdef ACCOUNTING
230 		acct_process(p);
231 #endif
232 
233 #ifdef KTRACE
234 		/* release trace file */
235 		if (pr->ps_tracevp)
236 			ktrcleartrace(pr);
237 #endif
238 
239 		/*
240 		 * If parent has the SAS_NOCLDWAIT flag set, we're not
241 		 * going to become a zombie.
242 		 */
243 		if (pr->ps_pptr->ps_mainproc->p_sigacts->ps_flags &
244 		    SAS_NOCLDWAIT)
245 			atomic_setbits_int(&pr->ps_flags, PS_NOZOMBIE);
246 	}
247 
248 #if NSYSTRACE > 0
249 	if (ISSET(p->p_flag, P_SYSTRACE))
250 		systrace_exit(p);
251 #endif
252 
253 	/*
254 	 * If emulation has process exit hook, call it now.
255 	 */
256 	if (p->p_emul->e_proc_exit)
257 		(*p->p_emul->e_proc_exit)(p);
258 
259         /*
260 	 * Remove proc from pidhash chain and allproc so looking
261 	 * it up won't work.  We will put the proc on the
262 	 * deadproc list later (using the p_hash member), and
263 	 * wake up the reaper when we do.  If this is the last
264 	 * thread of a process that isn't PS_NOZOMBIE, we'll put
265 	 * the process on the zombprocess list below.
266 	 */
267 	/*
268 	 * NOTE: WE ARE NO LONGER ALLOWED TO SLEEP!
269 	 */
270 	p->p_stat = SDEAD;
271 
272 	LIST_REMOVE(p, p_hash);
273 	LIST_REMOVE(p, p_list);
274 
275 	if ((p->p_flag & P_THREAD) == 0) {
276 		LIST_REMOVE(pr, ps_list);
277 
278 		if ((pr->ps_flags & PS_NOZOMBIE) == 0)
279 			LIST_INSERT_HEAD(&zombprocess, pr, ps_list);
280 		else {
281 			/*
282 			 * Not going to be a zombie, so it's now off all
283 			 * the lists scanned by ispidtaken(), so block
284 			 * fast reuse of the pid now.
285 			 */
286 			freepid(p->p_pid);
287 		}
288 
289 		/*
290 		 * Give orphaned children to init(8).
291 		 */
292 		qr = LIST_FIRST(&pr->ps_children);
293 		if (qr)		/* only need this if any child is S_ZOMB */
294 			wakeup(initproc->p_p);
295 		for (; qr != 0; qr = nqr) {
296 			nqr = LIST_NEXT(qr, ps_sibling);
297 			proc_reparent(qr, initproc->p_p);
298 			/*
299 			 * Traced processes are killed since their
300 			 * existence means someone is screwing up.
301 			 */
302 			if (qr->ps_flags & PS_TRACED &&
303 			    !(qr->ps_flags & PS_EXITING)) {
304 				atomic_clearbits_int(&qr->ps_flags, PS_TRACED);
305 				/*
306 				 * If single threading is active,
307 				 * direct the signal to the active
308 				 * thread to avoid deadlock.
309 				 */
310 				if (qr->ps_single)
311 					ptsignal(qr->ps_single, SIGKILL,
312 					    STHREAD);
313 				else
314 					prsignal(qr, SIGKILL);
315 			}
316 		}
317 	}
318 
319 	/* add thread's accumulated rusage into the process's total */
320 	ruadd(rup, &p->p_ru);
321 	tuagg(pr, p);
322 
323 	/*
324 	 * clear %cpu usage during swap
325 	 */
326 	p->p_pctcpu = 0;
327 
328 	if ((p->p_flag & P_THREAD) == 0) {
329 		/*
330 		 * Final thread has died, so add on our children's rusage
331 		 * and calculate the total times
332 		 */
333 		calcru(&pr->ps_tu, &rup->ru_utime, &rup->ru_stime, NULL);
334 		ruadd(rup, &pr->ps_cru);
335 
336 		/* notify interested parties of our demise and clean up */
337 		knote_processexit(pr);
338 
339 		/*
340 		 * Notify parent that we're gone.  If we're not going to
341 		 * become a zombie, reparent to process 1 (init) so that
342 		 * we can wake our original parent to possibly unblock
343 		 * wait4() to return ECHILD.
344 		 */
345 		if (pr->ps_flags & PS_NOZOMBIE) {
346 			struct process *ppr = pr->ps_pptr;
347 			proc_reparent(pr, initproc->p_p);
348 			wakeup(ppr);
349 		}
350 	}
351 
352 	/*
353 	 * Release the process's signal state.
354 	 */
355 	sigactsfree(p);
356 
357 	/* just a thread? detach it from its process */
358 	if (p->p_flag & P_THREAD) {
359 		/* scheduler_wait_hook(pr->ps_mainproc, p); XXX */
360 		--pr->ps_refcnt;
361 		KASSERT(pr->ps_refcnt > 0);
362 	}
363 
364 	/*
365 	 * Other substructures are freed from reaper and wait().
366 	 */
367 
368 	/*
369 	 * Finally, call machine-dependent code to switch to a new
370 	 * context (possibly the idle context).  Once we are no longer
371 	 * using the dead process's vmspace and stack, exit2() will be
372 	 * called to schedule those resources to be released by the
373 	 * reaper thread.
374 	 *
375 	 * Note that cpu_exit() will end with a call equivalent to
376 	 * cpu_switch(), finishing our execution (pun intended).
377 	 */
378 	uvmexp.swtch++;
379 	cpu_exit(p);
380 	panic("cpu_exit returned");
381 }
382 
383 /*
384  * Locking of this proclist is special; it's accessed in a
385  * critical section of process exit, and thus locking it can't
386  * modify interrupt state.  We use a simple spin lock for this
387  * proclist.  We use the p_hash member to linkup to deadproc.
388  */
389 struct mutex deadproc_mutex = MUTEX_INITIALIZER(IPL_NONE);
390 struct proclist deadproc = LIST_HEAD_INITIALIZER(deadproc);
391 
392 /*
393  * We are called from cpu_exit() once it is safe to schedule the
394  * dead process's resources to be freed.
395  *
396  * NOTE: One must be careful with locking in this routine.  It's
397  * called from a critical section in machine-dependent code, so
398  * we should refrain from changing any interrupt state.
399  *
400  * We lock the deadproc list, place the proc on that list (using
401  * the p_hash member), and wake up the reaper.
402  */
403 void
404 exit2(struct proc *p)
405 {
406 	mtx_enter(&deadproc_mutex);
407 	LIST_INSERT_HEAD(&deadproc, p, p_hash);
408 	mtx_leave(&deadproc_mutex);
409 
410 	wakeup(&deadproc);
411 }
412 
413 void
414 proc_free(struct proc *p)
415 {
416 	pool_put(&proc_pool, p);
417 	nthreads--;
418 }
419 
420 /*
421  * Process reaper.  This is run by a kernel thread to free the resources
422  * of a dead process.  Once the resources are free, the process becomes
423  * a zombie, and the parent is allowed to read the undead's status.
424  */
425 void
426 reaper(void)
427 {
428 	struct proc *p;
429 
430 	KERNEL_UNLOCK();
431 
432 	SCHED_ASSERT_UNLOCKED();
433 
434 	for (;;) {
435 		mtx_enter(&deadproc_mutex);
436 		while ((p = LIST_FIRST(&deadproc)) == NULL)
437 			msleep(&deadproc, &deadproc_mutex, PVM, "reaper", 0);
438 
439 		/* Remove us from the deadproc list. */
440 		LIST_REMOVE(p, p_hash);
441 		mtx_leave(&deadproc_mutex);
442 
443 		KERNEL_LOCK();
444 
445 		/*
446 		 * Free the VM resources we're still holding on to.
447 		 * We must do this from a valid thread because doing
448 		 * so may block.
449 		 */
450 		uvm_exit(p);
451 
452 		if (p->p_flag & P_THREAD) {
453 			/* Just a thread */
454 			proc_free(p);
455 		} else {
456 			struct process *pr = p->p_p;
457 
458 			if ((pr->ps_flags & PS_NOZOMBIE) == 0) {
459 				/* Process is now a true zombie. */
460 				p->p_stat = SZOMB;
461 				prsignal(pr->ps_pptr, SIGCHLD);
462 
463 				/* Wake up the parent so it can get exit status. */
464 				wakeup(pr->ps_pptr);
465 			} else {
466 				/* No one will wait for us. Just zap the process now */
467 				process_zap(pr);
468 			}
469 		}
470 
471 		KERNEL_UNLOCK();
472 	}
473 }
474 
475 int
476 sys_wait4(struct proc *q, void *v, register_t *retval)
477 {
478 	struct sys_wait4_args /* {
479 		syscallarg(pid_t) pid;
480 		syscallarg(int *) status;
481 		syscallarg(int) options;
482 		syscallarg(struct rusage *) rusage;
483 	} */ *uap = v;
484 	struct rusage ru;
485 	int status, error;
486 
487 	error = dowait4(q, SCARG(uap, pid),
488 	    SCARG(uap, status) ? &status : NULL,
489 	    SCARG(uap, options), SCARG(uap, rusage) ? &ru : NULL, retval);
490 	if (error == 0 && SCARG(uap, status)) {
491 		error = copyout(&status, SCARG(uap, status), sizeof(status));
492 	}
493 	if (error == 0 && SCARG(uap, rusage)) {
494 		error = copyout(&ru, SCARG(uap, rusage), sizeof(ru));
495 #ifdef KTRACE
496 		if (error == 0 && KTRPOINT(q, KTR_STRUCT))
497 			ktrrusage(q, &ru);
498 #endif
499 	}
500 	return (error);
501 }
502 
503 int
504 dowait4(struct proc *q, pid_t pid, int *statusp, int options,
505     struct rusage *rusage, register_t *retval)
506 {
507 	int nfound;
508 	struct process *pr;
509 	struct proc *p;
510 	int error;
511 
512 	if (pid == 0)
513 		pid = -q->p_p->ps_pgid;
514 	if (options &~ (WUNTRACED|WNOHANG|WCONTINUED))
515 		return (EINVAL);
516 
517 loop:
518 	nfound = 0;
519 	LIST_FOREACH(pr, &q->p_p->ps_children, ps_sibling) {
520 		p = pr->ps_mainproc;
521 		if ((pr->ps_flags & PS_NOZOMBIE) ||
522 		    (pid != WAIT_ANY &&
523 		    p->p_pid != pid &&
524 		    pr->ps_pgid != -pid))
525 			continue;
526 
527 		nfound++;
528 		if (p->p_stat == SZOMB) {
529 			retval[0] = p->p_pid;
530 
531 			if (statusp != NULL)
532 				*statusp = p->p_xstat;	/* convert to int */
533 			if (rusage != NULL)
534 				memcpy(rusage, pr->ps_ru, sizeof(*rusage));
535 			proc_finish_wait(q, p);
536 			return (0);
537 		}
538 		if (pr->ps_flags & PS_TRACED &&
539 		    (pr->ps_flags & PS_WAITED) == 0 && pr->ps_single &&
540 		    pr->ps_single->p_stat == SSTOP &&
541 		    (pr->ps_single->p_flag & P_SUSPSINGLE) == 0) {
542 			single_thread_wait(pr);
543 
544 			atomic_setbits_int(&pr->ps_flags, PS_WAITED);
545 			retval[0] = p->p_pid;
546 
547 			if (statusp != NULL)
548 				*statusp = W_STOPCODE(pr->ps_single->p_xstat);
549 			return (0);
550 		}
551 		if (p->p_stat == SSTOP &&
552 		    (pr->ps_flags & PS_WAITED) == 0 &&
553 		    (p->p_flag & P_SUSPSINGLE) == 0 &&
554 		    (pr->ps_flags & PS_TRACED ||
555 		    options & WUNTRACED)) {
556 			atomic_setbits_int(&pr->ps_flags, PS_WAITED);
557 			retval[0] = p->p_pid;
558 
559 			if (statusp != NULL)
560 				*statusp = W_STOPCODE(p->p_xstat);
561 			return (0);
562 		}
563 		if ((options & WCONTINUED) && (p->p_flag & P_CONTINUED)) {
564 			atomic_clearbits_int(&p->p_flag, P_CONTINUED);
565 			retval[0] = p->p_pid;
566 
567 			if (statusp != NULL)
568 				*statusp = _WCONTINUED;
569 			return (0);
570 		}
571 	}
572 	if (nfound == 0)
573 		return (ECHILD);
574 	if (options & WNOHANG) {
575 		retval[0] = 0;
576 		return (0);
577 	}
578 	if ((error = tsleep(q->p_p, PWAIT | PCATCH, "wait", 0)) != 0)
579 		return (error);
580 	goto loop;
581 }
582 
583 void
584 proc_finish_wait(struct proc *waiter, struct proc *p)
585 {
586 	struct process *pr, *tr;
587 	struct rusage *rup;
588 
589 	/*
590 	 * If we got the child via a ptrace 'attach',
591 	 * we need to give it back to the old parent.
592 	 */
593 	pr = p->p_p;
594 	if (pr->ps_oppid && (tr = prfind(pr->ps_oppid))) {
595 		atomic_clearbits_int(&pr->ps_flags, PS_TRACED);
596 		pr->ps_oppid = 0;
597 		proc_reparent(pr, tr);
598 		prsignal(tr, SIGCHLD);
599 		wakeup(tr);
600 	} else {
601 		scheduler_wait_hook(waiter, p);
602 		p->p_xstat = 0;
603 		rup = &waiter->p_p->ps_cru;
604 		ruadd(rup, pr->ps_ru);
605 		LIST_REMOVE(pr, ps_list);	/* off zombprocess */
606 		freepid(p->p_pid);
607 		process_zap(pr);
608 	}
609 }
610 
611 /*
612  * make process 'parent' the new parent of process 'child'.
613  */
614 void
615 proc_reparent(struct process *child, struct process *parent)
616 {
617 
618 	if (child->ps_pptr == parent)
619 		return;
620 
621 	LIST_REMOVE(child, ps_sibling);
622 	LIST_INSERT_HEAD(&parent->ps_children, child, ps_sibling);
623 	child->ps_pptr = parent;
624 }
625 
626 void
627 process_zap(struct process *pr)
628 {
629 	struct vnode *otvp;
630 	struct proc *p = pr->ps_mainproc;
631 
632 	/*
633 	 * Finally finished with old proc entry.
634 	 * Unlink it from its process group and free it.
635 	 */
636 	leavepgrp(pr);
637 	LIST_REMOVE(pr, ps_sibling);
638 
639 	/*
640 	 * Decrement the count of procs running with this uid.
641 	 */
642 	(void)chgproccnt(pr->ps_cred->p_ruid, -1);
643 
644 	/*
645 	 * Release reference to text vnode
646 	 */
647 	otvp = pr->ps_textvp;
648 	pr->ps_textvp = NULL;
649 	if (otvp)
650 		vrele(otvp);
651 
652 	KASSERT(pr->ps_refcnt == 1);
653 	if (pr->ps_ptstat != NULL)
654 		free(pr->ps_ptstat, M_SUBPROC);
655 	pool_put(&rusage_pool, pr->ps_ru);
656 	KASSERT(TAILQ_EMPTY(&pr->ps_threads));
657 	limfree(pr->ps_limit);
658 	crfree(pr->ps_cred->pc_ucred);
659 	pool_put(&pcred_pool, pr->ps_cred);
660 	pool_put(&process_pool, pr);
661 	nprocesses--;
662 
663 	proc_free(p);
664 }
665