MCPcopy Create free account
hub / github.com/F-Stack/f-stack / tty_info

Function tty_info

freebsd/kern/tty_info.c:277–406  ·  view source on GitHub ↗

* Report on state of foreground process group. */

Source from the content-addressed store, hash-verified

275 * Report on state of foreground process group.
276 */
277void
278tty_info(struct tty *tp)
279{
280 struct timeval rtime, utime, stime;
281#ifdef STACK
282 struct stack stack;
283 int sterr, kstacks_val;
284 bool print_kstacks;
285#endif
286 struct proc *p, *ppick;
287 struct thread *td, *tdpick;
288 const char *stateprefix, *state;
289 struct sbuf sb;
290 long rss;
291 int load, pctcpu;
292 pid_t pid;
293 char comm[MAXCOMLEN + 1];
294 struct rusage ru;
295
296 tty_assert_locked(tp);
297
298 if (tty_checkoutq(tp) == 0)
299 return;
300
301 (void)sbuf_new(&sb, tp->t_prbuf, tp->t_prbufsz, SBUF_FIXEDLEN);
302 sbuf_set_drain(&sb, sbuf_tty_drain, tp);
303
304 /* Print load average. */
305 load = (averunnable.ldavg[0] * 100 + FSCALE / 2) >> FSHIFT;
306 sbuf_printf(&sb, "%sload: %d.%02d ", tp->t_column == 0 ? "" : "\n",
307 load / 100, load % 100);
308
309 if (tp->t_session == NULL) {
310 sbuf_printf(&sb, "not a controlling terminal\n");
311 goto out;
312 }
313 if (tp->t_pgrp == NULL) {
314 sbuf_printf(&sb, "no foreground process group\n");
315 goto out;
316 }
317 PGRP_LOCK(tp->t_pgrp);
318 if (LIST_EMPTY(&tp->t_pgrp->pg_members)) {
319 PGRP_UNLOCK(tp->t_pgrp);
320 sbuf_printf(&sb, "empty foreground process group\n");
321 goto out;
322 }
323
324 /*
325 * Pick the most interesting process and copy some of its
326 * state for printing later. This operation could rely on stale
327 * data as we can't hold the proc slock or thread locks over the
328 * whole list. However, we're guaranteed not to reference an exited
329 * thread or proc since we hold the tty locked.
330 */
331 p = NULL;
332 LIST_FOREACH(ppick, &tp->t_pgrp->pg_members, p_pglist)
333 if (proc_compare(p, ppick))
334 p = ppick;

Callers 2

tty_signal_pgrpFunction · 0.85
tty_generic_ioctlFunction · 0.85

Calls 15

tty_checkoutqFunction · 0.85
sbuf_newFunction · 0.85
sbuf_set_drainFunction · 0.85
sbuf_printfFunction · 0.85
proc_compareFunction · 0.85
thread_compareFunction · 0.85
vmspace_resident_countFunction · 0.85
microuptimeFunction · 0.85
rufetchcalcFunction · 0.85
stack_sbuf_print_flagsFunction · 0.85
sbuf_finishFunction · 0.85
sbuf_deleteFunction · 0.85

Tested by

no test coverage detected