From owner-freebsd-hackers@FreeBSD.ORG Sun Mar 8 14:20:07 2009 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 723FE106564A for ; Sun, 8 Mar 2009 14:20:07 +0000 (UTC) (envelope-from freebsd@jayloden.com) Received: from mail.jayloden.com (www.jayloden.com [66.150.227.71]) by mx1.freebsd.org (Postfix) with ESMTP id 516AB8FC16 for ; Sun, 8 Mar 2009 14:20:07 +0000 (UTC) (envelope-from freebsd@jayloden.com) Received: from [192.168.15.104] (c-98-221-217-95.hsd1.nj.comcast.net [98.221.217.95]) by mail.jayloden.com (Postfix) with ESMTP id 252CB3160205 for ; Sun, 8 Mar 2009 10:03:12 -0400 (EDT) Message-ID: <49B3D01E.1010600@jayloden.com> Date: Sun, 08 Mar 2009 10:03:10 -0400 From: Jay Loden User-Agent: Thunderbird 2.0.0.19 (Macintosh/20081209) MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: CPU user/kernel time given the PID X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Mar 2009 14:20:07 -0000 I'm working on FreeBSD support for a Python library called psutil for reading process information in a cross-platform fashion. Each platform-specific module is written in C, so the majority of the FreeBSD code is a C interface to various process information. I've been having some trouble working out how to get CPU user/kernel time for a given PID. I took a look at the source to top and ps but neither really helped since they don't seem to cover the info I was looking for (or I missed it). I'm not sure if there's a better way to go about this but I've been looking at sysctl and the kinfo_proc struct - is there somewhere more appropriate to retrieve this information? If the kinfo_proc struct is the way to go, then do I want to use ki_runtime, ki_swtime or something else, and does that mean there's no distinction between user/kern time for a process? If anyone has code samples or recommended docs to get me pointed in the right direction that would be great. Thanks, -Jay