FreeBSD/sys/kern/kern_proc.c
/*
 * stop_all_proc() purpose is to stop all process which have usermode,
 * except current process for obvious reasons.  This makes it somewhat
 * unreliable when invoked from multithreaded process.  The service
 * must not be user-callable anyway.
 */
stop_all_proc() purpose is to stop all process which have usermode,
except current process for obvious reasons.  This makes it somewhat
unreliable when invoked from multithreaded process.  The service
must not be user-callable anyway.
stop_all_proc () purpose is to stop all process which have usermode except current process for obvious reasons . This makes it somewhat unreliable when invoked from multithreaded process . The service must not be user - callable anyway .
void
stop_all_proc(void)
{
	struct proc *cp, *p;
	int r, gen;
	bool restart, seen_stopped, seen_exiting, stopped_some;
	cp = curproc;
allproc_loop:
	sx_xlock(&allproc_lock);
	gen = allproc_gen;
	seen_exiting = seen_stopped = stopped_some = restart = false;
	LIST_REMOVE(cp, p_list);
	LIST_INSERT_HEAD(&allproc, cp, p_list);
	for (;;) {
		p = LIST_NEXT(cp, p_list);
		if (p == NULL)
			break;
		LIST_REMOVE(cp, p_list);
		LIST_INSERT_AFTER(p, cp, p_list);
		PROC_LOCK(p);
		if ((p->p_flag & (P_KPROC | P_SYSTEM | P_TOTAL_STOP)) != 0) {
			PROC_UNLOCK(p);
			continue;
		}
		if ((p->p_flag & P_WEXIT) != 0) {
			seen_exiting = true;
			PROC_UNLOCK(p);
			continue;
		}
		if (P_SHOULDSTOP(p) == P_STOPPED_SINGLE) {
			seen_stopped = true;
			PROC_UNLOCK(p);
			continue;
		}
		_PHOLD(p);
		sx_xunlock(&allproc_lock);
		r = thread_single(p, SINGLE_ALLPROC);
		if (r != 0)
			restart = true;
		else
			stopped_some = true;
		_PRELE(p);
		PROC_UNLOCK(p);
		sx_xlock(&allproc_lock);
	}
	if (gen != allproc_gen)
		restart = true;
	sx_xunlock(&allproc_lock);
	if (restart || stopped_some || seen_exiting || seen_stopped) {
		kern_yield(PRI_USER);
		goto allproc_loop;
	}
}
void stop_all_proc ( void ) { struct proc * cp , * p ; int r , gen ; bool restart , seen_stopped , seen_exiting , stopped_some ; cp = curproc ; allproc_loop : sx_xlock ( & allproc_lock ) ; gen = allproc_gen ; seen_exiting = seen_stopped = stopped_some = restart = false ; LIST_REMOVE ( cp , p_list ) ; LIST_INSERT_HEAD ( & allproc , cp , p_list ) ; for ( ; ; ) { p = LIST_NEXT ( cp , p_list ) ; if ( p == NULL ) break ; LIST_REMOVE ( cp , p_list ) ; LIST_INSERT_AFTER ( p , cp , p_list ) ; PROC_LOCK ( p ) ; if ( ( p -> p_flag & ( P_KPROC | P_SYSTEM | P_TOTAL_STOP ) ) != 0 ) { PROC_UNLOCK ( p ) ; continue ; } if ( ( p -> p_flag & P_WEXIT ) != 0 ) { seen_exiting = true ; PROC_UNLOCK ( p ) ; continue ; } if ( P_SHOULDSTOP ( p ) == P_STOPPED_SINGLE ) { seen_stopped = true ; PROC_UNLOCK ( p ) ; continue ; } _PHOLD ( p ) ; sx_xunlock ( & allproc_lock ) ; r = thread_single ( p , SINGLE_ALLPROC ) ; if ( r != 0 ) restart = true ; else stopped_some = true ; _PRELE ( p ) ; PROC_UNLOCK ( p ) ; sx_xlock ( & allproc_lock ) ; } if ( gen != allproc_gen ) restart = true ; sx_xunlock ( & allproc_lock ) ; if ( restart || stopped_some || seen_exiting || seen_stopped ) { kern_yield ( PRI_USER ) ; goto allproc_loop ; } }
stop_all_proc() purpose is to stop all process which have usermode,
 except current process for obvious reasons.
stop_all_proc () purpose is to stop all process which have usermode except current process for obvious reasons .
/*
			 * Stopped processes are tolerated when there
			 * are no other processes which might continue
			 * them.  P_STOPPED_SINGLE but not
			 * P_TOTAL_STOP process still has at least one
			 * thread running.
			 */ /* Catch forked children we did not see in iteration. */