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

Function proc_compare

freebsd/kern/tty_info.c:166–218  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

164}
165
166static int
167proc_compare(struct proc *p1, struct proc *p2)
168{
169
170 int runa, runb;
171 fixpt_t esta, estb;
172
173 if (p1 == NULL)
174 return (1);
175
176 /*
177 * Fetch various stats about these processes. After we drop the
178 * lock the information could be stale but the race is unimportant.
179 */
180 PROC_LOCK(p1);
181 runa = proc_sum(p1, &esta);
182 PROC_UNLOCK(p1);
183 PROC_LOCK(p2);
184 runb = proc_sum(p2, &estb);
185 PROC_UNLOCK(p2);
186
187 /*
188 * see if at least one of them is runnable
189 */
190 switch (TESTAB(runa, runb)) {
191 case ONLYA:
192 return (0);
193 case ONLYB:
194 return (1);
195 case BOTH:
196 break;
197 }
198 /*
199 * favor one with highest recent cpu utilization
200 */
201 if (estb > esta)
202 return (1);
203 if (esta > estb)
204 return (0);
205 /*
206 * weed out zombies
207 */
208 switch (TESTAB(p1->p_state == PRS_ZOMBIE, p2->p_state == PRS_ZOMBIE)) {
209 case ONLYA:
210 return (1);
211 case ONLYB:
212 return (0);
213 case BOTH:
214 break;
215 }
216
217 return (p2->p_pid > p1->p_pid); /* tie - return highest pid */
218}
219
220static int
221sbuf_tty_drain(void *a, const char *d, int len)

Callers 1

tty_infoFunction · 0.85

Calls 1

proc_sumFunction · 0.85

Tested by

no test coverage detected