From owner-freebsd-questions@FreeBSD.ORG Thu Nov 19 17:01:47 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1048D1065670 for ; Thu, 19 Nov 2009 17:01:47 +0000 (UTC) (envelope-from cronfy@sprinthost.ru) Received: from odin.from.sh (odin.from.sh [80.93.50.112]) by mx1.freebsd.org (Postfix) with ESMTP id AA9668FC26 for ; Thu, 19 Nov 2009 17:01:46 +0000 (UTC) Received: from odin.from.sh ([80.93.50.112]) by odin.from.sh with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69 (FreeBSD)) (envelope-from ) id 1NBANs-000083-BV for freebsd-questions@freebsd.org; Thu, 19 Nov 2009 20:01:28 +0300 Received: from [89.223.116.161] (helo=[10.10.10.120]) by odin.from.sh with esmtpa (Exim 4.69 (FreeBSD)) (envelope-from ) id 1NBANl-00006D-52 for freebsd-questions@freebsd.org; Thu, 19 Nov 2009 20:01:21 +0300 Message-ID: <4B0579CE.2020203@sprinthost.ru> Date: Thu, 19 Nov 2009 20:01:02 +0300 From: cronfy User-Agent: Thunderbird 2.0.0.23 (X11/20090817) MIME-Version: 1.0 To: FreeBSD References: <4B042C50.6060904@sprinthost.ru> <5f09d2bccc69d1f101c5c22151ef0c05@sbmail.office-on-the.net> In-Reply-To: <5f09d2bccc69d1f101c5c22151ef0c05@sbmail.office-on-the.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: get accounting info for running process X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 19 Nov 2009 17:01:47 -0000 >> Is it possible to find out how much a process have used CPU user >> time/system time/IO operations for now by it's pid? Like in sa, but for >> running process. >> Dan, Mel, thanks for your answers. I examined 'ps' sources and decided to use kvm_getprocs() and rusage structure. I am trying to create a daemon that would report system accounting stats for every X seconds, let's say 10. 'sa' reports about terminated processes only, but it would be nice to have more detailed system usage stats per user for a given time interval (i.e. last 10 seconds), including tasks that are not finished at the moment of querying. I can achieve this by querying list of processes each 10 seconds and producing diffs between previous and current list, saving these to some log and combining data with /var/account/acct file. The only thing I do not want to do is to invent a wheel ;-) I googled much for such solutions, but did not find any. May be someone knows existing products that has this functionality already? Thanks in advance.