tty_info.c (180801) | tty_info.c (181905) |
---|---|
1/*- 2 * Copyright (c) 1982, 1986, 1990, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 27 unchanged lines hidden (view full) --- 36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 40 * SUCH DAMAGE. 41 */ 42 43#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1982, 1986, 1990, 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. --- 27 unchanged lines hidden (view full) --- 36 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 37 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 38 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 39 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 40 * SUCH DAMAGE. 41 */ 42 43#include <sys/cdefs.h> |
44__FBSDID("$FreeBSD: head/sys/kern/tty_info.c 180801 2008-07-25 14:31:00Z ed $"); | 44__FBSDID("$FreeBSD: head/sys/kern/tty_info.c 181905 2008-08-20 08:31:58Z ed $"); |
45 46#include <sys/param.h> 47#include <sys/lock.h> 48#include <sys/mutex.h> 49#include <sys/proc.h> 50#include <sys/resourcevar.h> 51#include <sys/sched.h> 52#include <sys/systm.h> --- 153 unchanged lines hidden (view full) --- 206 207 return (p2->p_pid > p1->p_pid); /* tie - return highest pid */ 208} 209 210/* 211 * Report on state of foreground process group. 212 */ 213void | 45 46#include <sys/param.h> 47#include <sys/lock.h> 48#include <sys/mutex.h> 49#include <sys/proc.h> 50#include <sys/resourcevar.h> 51#include <sys/sched.h> 52#include <sys/systm.h> --- 153 unchanged lines hidden (view full) --- 206 207 return (p2->p_pid > p1->p_pid); /* tie - return highest pid */ 208} 209 210/* 211 * Report on state of foreground process group. 212 */ 213void |
214ttyinfo(struct tty *tp) | 214tty_info(struct tty *tp) |
215{ 216 struct timeval utime, stime; 217 struct proc *p, *pick; 218 struct thread *td, *picktd; 219 const char *stateprefix, *state; 220 long rss; 221 int load, pctcpu; 222 pid_t pid; 223 char comm[MAXCOMLEN + 1]; 224 struct rusage ru; 225 | 215{ 216 struct timeval utime, stime; 217 struct proc *p, *pick; 218 struct thread *td, *picktd; 219 const char *stateprefix, *state; 220 long rss; 221 int load, pctcpu; 222 pid_t pid; 223 char comm[MAXCOMLEN + 1]; 224 struct rusage ru; 225 |
226 if (ttycheckoutq(tp,0) == 0) | 226 tty_lock_assert(tp, MA_OWNED); 227 228 if (tty_checkoutq(tp) == 0) |
227 return; 228 229 /* Print load average. */ 230 load = (averunnable.ldavg[0] * 100 + FSCALE / 2) >> FSHIFT; 231 ttyprintf(tp, "load: %d.%02d ", load / 100, load % 100); 232 | 229 return; 230 231 /* Print load average. */ 232 load = (averunnable.ldavg[0] * 100 + FSCALE / 2) >> FSHIFT; 233 ttyprintf(tp, "load: %d.%02d ", load / 100, load % 100); 234 |
233 /* 234 * On return following a ttyprintf(), we set tp->t_rocount to 0 so 235 * that pending input will be retyped on BS. 236 */ | |
237 if (tp->t_session == NULL) { 238 ttyprintf(tp, "not a controlling terminal\n"); | 235 if (tp->t_session == NULL) { 236 ttyprintf(tp, "not a controlling terminal\n"); |
239 tp->t_rocount = 0; | |
240 return; 241 } 242 if (tp->t_pgrp == NULL) { 243 ttyprintf(tp, "no foreground process group\n"); | 237 return; 238 } 239 if (tp->t_pgrp == NULL) { 240 ttyprintf(tp, "no foreground process group\n"); |
244 tp->t_rocount = 0; | |
245 return; 246 } 247 PGRP_LOCK(tp->t_pgrp); 248 if (LIST_EMPTY(&tp->t_pgrp->pg_members)) { 249 PGRP_UNLOCK(tp->t_pgrp); 250 ttyprintf(tp, "empty foreground process group\n"); | 241 return; 242 } 243 PGRP_LOCK(tp->t_pgrp); 244 if (LIST_EMPTY(&tp->t_pgrp->pg_members)) { 245 PGRP_UNLOCK(tp->t_pgrp); 246 ttyprintf(tp, "empty foreground process group\n"); |
251 tp->t_rocount = 0; | |
252 return; 253 } 254 255 /* 256 * Pick the most interesting process and copy some of its 257 * state for printing later. This operation could rely on stale 258 * data as we can't hold the proc slock or thread locks over the 259 * whole list. However, we're guaranteed not to reference an exited --- 48 unchanged lines hidden (view full) --- 308 309 /* Print command, pid, state, utime, stime, %cpu, and rss. */ 310 ttyprintf(tp, 311 " cmd: %s %d [%s%s] %ld.%02ldu %ld.%02lds %d%% %ldk\n", 312 comm, pid, stateprefix, state, 313 (long)utime.tv_sec, utime.tv_usec / 10000, 314 (long)stime.tv_sec, stime.tv_usec / 10000, 315 pctcpu / 100, rss); | 247 return; 248 } 249 250 /* 251 * Pick the most interesting process and copy some of its 252 * state for printing later. This operation could rely on stale 253 * data as we can't hold the proc slock or thread locks over the 254 * whole list. However, we're guaranteed not to reference an exited --- 48 unchanged lines hidden (view full) --- 303 304 /* Print command, pid, state, utime, stime, %cpu, and rss. */ 305 ttyprintf(tp, 306 " cmd: %s %d [%s%s] %ld.%02ldu %ld.%02lds %d%% %ldk\n", 307 comm, pid, stateprefix, state, 308 (long)utime.tv_sec, utime.tv_usec / 10000, 309 (long)stime.tv_sec, stime.tv_usec / 10000, 310 pctcpu / 100, rss); |
316 tp->t_rocount = 0; | |
317} | 311} |