From owner-freebsd-hackers@FreeBSD.ORG Sun Jan 24 23:59:08 2010 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 CF841106566C for ; Sun, 24 Jan 2010 23:59:08 +0000 (UTC) (envelope-from cronfy@gmail.com) Received: from mail-fx0-f226.google.com (mail-fx0-f226.google.com [209.85.220.226]) by mx1.freebsd.org (Postfix) with ESMTP id 68EA48FC19 for ; Sun, 24 Jan 2010 23:59:06 +0000 (UTC) Received: by fxm26 with SMTP id 26so547010fxm.13 for ; Sun, 24 Jan 2010 15:59:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:from:date:message-id :subject:to:content-type; bh=zDMHhv3641GK7wAxiZpc6LTohSL/pB131OACu47q9no=; b=IDdPLKqTCtBt+CNzXnWlD4Oss4iwYmuPiri65BE58jKaStb1djeH7rUiqUh1jjEcWP wZ+MJ6+kGsM7HRnxmlhthM885OO/l2yObQG8yAQIJlea/jNVcaciyFWAmDnSS5JVNy5Y oyvPLWUOrGCy3e67DU6RVldeoAcCf9epzDzT8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=Zj16a0P4goJaWsDFnBYEi1+T0qho5psSldTOnT/nhnz2z+R5SdJdKKTp32DlPHFbtb GU85R6/w+u2s2l12YcU1flNRzu6SVm96dndRNDndvDLn2dAFU69qgWIDVC0QJBPbCKiP Cvr3umRV7Ti4MKoIs0qbhFkSqd7RbVeK2bQPE= MIME-Version: 1.0 Received: by 10.223.63.193 with SMTP id c1mr6020791fai.80.1264376035103; Sun, 24 Jan 2010 15:33:55 -0800 (PST) From: cronfy Date: Mon, 25 Jan 2010 02:33:35 +0300 Message-ID: To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 Subject: Unique process id (not pid) and accounting daemon 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, 24 Jan 2010 23:59:08 -0000 Hello. Sorry for the crosspost, I intended to post this to freebsd-hackers@, but sent first copy to freebsd-questions@ by mistake. I am trying to create an accounting daemon that would be more precise than usual BSD system accounting. It should read the whole process tree from time to time (say, every 10 seconds) and log changes in usage of CPU, I/O operations and memory per process. After daemon notices process exit, it should read /var/account/acct to get a last portion of accounting data and make a last entry for the process. Also daemon should read /var/account/acct to find information about processes that had been running between taking process tree snapshots. There is a problem: it is not always possible to link a process in a process tree against matching process in an accounting file. Only command name, user/group id and start time will match, but: * start time may change (i. e. after ntpdate); * command name saved in /var/account/acct is 15 characters max (AC_COMM_LEN in sys/sys/acct.h), while command name in the process tree is 19 characters max (MAXCOMLEN in sys/sys/param.h). To ensure that process in the process tree and process in the accounting file are the same, I want to add unique process identifier (uint64_t) to 'proc' struct in sys/sys/proc.h and increment it for every process fork. I see it is possible to do this just before sx_sunlock() in fork1() in sys/kern/kern_fork.c. I'll have to add saving of this identifier in kern_acct.c, of course. This way I will be extremely easy to remember a process in the process tree and find a matching one in the accounting file after it finishes. Am I looking in a right direction or should I try some other way? Thanks in advance. -- // cronfy