1*dba3562dSLionel Sambuc.\" $NetBSD: proc_compare.3,v 1.2 2011/10/21 12:58:53 wiz Exp $ 2*dba3562dSLionel Sambuc.\" 3*dba3562dSLionel Sambuc.\" Copyright (c) 2011 The NetBSD Foundation, Inc. 4*dba3562dSLionel Sambuc.\" All rights reserved. 5*dba3562dSLionel Sambuc.\" 6*dba3562dSLionel Sambuc.\" This code is derived from software contributed to The NetBSD Foundation 7*dba3562dSLionel Sambuc.\" by Christos Zoulas. 8*dba3562dSLionel Sambuc.\" 9*dba3562dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without 10*dba3562dSLionel Sambuc.\" modification, are permitted provided that the following conditions 11*dba3562dSLionel Sambuc.\" are met: 12*dba3562dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright 13*dba3562dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer. 14*dba3562dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright 15*dba3562dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer in the 16*dba3562dSLionel Sambuc.\" documentation and/or other materials provided with the distribution. 17*dba3562dSLionel Sambuc.\" 3. All advertising materials mentioning features or use of this software 18*dba3562dSLionel Sambuc.\" must display the following acknowledgement: 19*dba3562dSLionel Sambuc.\" This product includes software developed by the NetBSD 20*dba3562dSLionel Sambuc.\" Foundation, Inc. and its contributors. 21*dba3562dSLionel Sambuc.\" 4. Neither the name of The NetBSD Foundation nor the names of its 22*dba3562dSLionel Sambuc.\" contributors may be used to endorse or promote products derived 23*dba3562dSLionel Sambuc.\" from this software without specific prior written permission. 24*dba3562dSLionel Sambuc.\" 25*dba3562dSLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26*dba3562dSLionel Sambuc.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27*dba3562dSLionel Sambuc.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28*dba3562dSLionel Sambuc.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29*dba3562dSLionel Sambuc.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30*dba3562dSLionel Sambuc.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31*dba3562dSLionel Sambuc.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32*dba3562dSLionel Sambuc.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33*dba3562dSLionel Sambuc.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34*dba3562dSLionel Sambuc.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35*dba3562dSLionel Sambuc.\" POSSIBILITY OF SUCH DAMAGE. 36*dba3562dSLionel Sambuc.\" 37*dba3562dSLionel Sambuc.\" 38*dba3562dSLionel Sambuc.Dd October 20, 2011 39*dba3562dSLionel Sambuc.Dt PROC_COMPARE 3 40*dba3562dSLionel Sambuc.Os 41*dba3562dSLionel Sambuc.Sh NAME 42*dba3562dSLionel Sambuc.Nm proc_compare 43*dba3562dSLionel Sambuc.Nd compare two processes' interactivity 44*dba3562dSLionel Sambuc.Sh LIBRARY 45*dba3562dSLionel Sambuc.Lb libutil 46*dba3562dSLionel Sambuc.Sh SYNOPSIS 47*dba3562dSLionel Sambuc.In sys/sysctl.h 48*dba3562dSLionel Sambuc.Ft int 49*dba3562dSLionel Sambuc.Fn "proc_compare" "const struct kinfo_proc2 *p1" "const struct kinfo_lwp *l1" \ 50*dba3562dSLionel Sambuc"const struct kinfo_proc2 *p2" "const struct kinfo_lwp *l2" 51*dba3562dSLionel Sambuc.Sh DESCRIPTION 52*dba3562dSLionel SambucThe 53*dba3562dSLionel Sambuc.Fn proc_compare 54*dba3562dSLionel Sambucfunction compares two processes that are on the same terminal for their 55*dba3562dSLionel Sambucinteractivity. 56*dba3562dSLionel SambucThis means that the process returned is the one that has a better chance 57*dba3562dSLionel Sambucbeing the active foreground process on that tty. 58*dba3562dSLionel SambucThis algorithm is used in the kernel for 59*dba3562dSLionel Sambuc.Dv SIGINFO 60*dba3562dSLionel Sambucreporting and in userland by 61*dba3562dSLionel Sambuc.Xr w 1 . 62*dba3562dSLionel Sambuc.Pp 63*dba3562dSLionel SambucThe algorithm used is as follows: 64*dba3562dSLionel Sambuc.Bl -bullet -compact -offset indent 65*dba3562dSLionel Sambuc.It 66*dba3562dSLionel SambucIf one of them is runnable, it is preferred. 67*dba3562dSLionel Sambuc.It 68*dba3562dSLionel SambucIf both are runnable, the one with the largest CPU percent is preferred. 69*dba3562dSLionel Sambuc.It 70*dba3562dSLionel SambucIn a CPU percent tie, the one started more recently wins. 71*dba3562dSLionel Sambuc.It 72*dba3562dSLionel SambucIf none are runnable, and one of them is a zombie, the non-zombie is preferred 73*dba3562dSLionel Sambuc.It 74*dba3562dSLionel SambucIf both are zombies, the one started more recently wins. 75*dba3562dSLionel Sambuc.It 76*dba3562dSLionel SambucIf neither is a zombie, the one with the smaller sleep time wins. 77*dba3562dSLionel Sambuc.It 78*dba3562dSLionel SambucIn a tie, and one is sleeping in non-interruptible sleep, prefer that one. 79*dba3562dSLionel Sambuc.It 80*dba3562dSLionel SambucIf both are in the same state, the one started more recently is preferred. 81*dba3562dSLionel Sambuc.El 82*dba3562dSLionel SambucIn all cases where the most recently started wins, if there was no winner, 83*dba3562dSLionel Sambucthe one with the largest PID wins. 84*dba3562dSLionel Sambuc.Sh RETURN VALUES 85*dba3562dSLionel SambucThe 86*dba3562dSLionel Sambuc.Fn proc_compare 87*dba3562dSLionel Sambucfunction returns 88*dba3562dSLionel Sambuc.Dv 0 89*dba3562dSLionel Sambucif 90*dba3562dSLionel Sambuc.Fa p1 91*dba3562dSLionel Sambucis to be preferred 92*dba3562dSLionel Sambucand 93*dba3562dSLionel Sambuc.Dv 1 94*dba3562dSLionel Sambucif 95*dba3562dSLionel Sambuc.Fa p2 96*dba3562dSLionel Sambucis to be preferred. 97*dba3562dSLionel Sambuc.Sh SEE ALSO 98*dba3562dSLionel Sambuc.Xr w 1 99*dba3562dSLionel Sambuc.Sh HISTORY 100*dba3562dSLionel SambucThe 101*dba3562dSLionel Sambuc.Fn proc_compare 102*dba3562dSLionel Sambucwas extracted from 103*dba3562dSLionel Sambuc.Pa src/sys/kern/tty.c 104*dba3562dSLionel Sambucand 105*dba3562dSLionel Sambuc.Pa src/usr.bin/w/proc_compare.c 106*dba3562dSLionel Sambucand merged in 107*dba3562dSLionel Sambuc.Nx 6.0 . 108