公司簡介
介紹
/* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of th
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */
詳細
#ifndef _SYS_ACCT_H
#define _SYS_ACCT_H 1
#include <features.h>
#define __need_time_t
#include <time.h>
#include <sys/types.h>
__BEGIN_DECLS
#define ACCT_COMM 16
comp_t is a 16-bit "floating" point number with a 3-bit base 8
exponent and a 13-bit fraction. See linux/kernel/acct.c for the
specific encoding system used.
typedef u_int16_t comp_t;
struct acct
char ac_flag; /* Accounting flags. */
u_int16_t ac_uid; /* Accounting user ID. */
u_int16_t ac_gid; /* Accounting group ID. */
u_int16_t ac_tty; /* Controlling tty. */
u_int32_t ac_btime; /* Beginning time. */
comp_t ac_utime; /* Accounting user time. */
comp_t ac_stime; /* Accounting system time. */
comp_t ac_etime; /* Accounting elapsed time. */
comp_t ac_mem; /* Accounting average memory usage. */
comp_t ac_io; /* Accounting chars transferred. */
comp_t ac_rw; /* Accounting blocks read or written. */
comp_t ac_minflt; /* Accounting minor pagefaults. */
comp_t ac_majflt; /* Accounting major pagefaults. */
comp_t ac_swaps; /* Accounting number of swaps. */
u_int32_t ac_exitcode; /* Accounting process exitcode. */
char ac_comm[ACCT_COMM+1]; /* Accounting command name. */
char ac_pad[10]; /* Accounting padding bytes. */
};
enum
{
AFORK = 0x01, /* Has executed fork, but no exec. */
ASU = 0x02, /* Used super-user privileges. */
ACORE = 0x08, /* Dumped core. */
AXSIG = 0x10 /* Killed by a signal. */
};
#define AHZ 100
/* Switch process accounting on and off. */
extern int acct (__const char *__filename) __THROW;
__END_DECLS
#endif /* sys/acct.h */
文庫:
Standard C Library (libc, -lc)
概要:
#include <unistd.h>
int acct(const char * file, int mode);
詳述:
acct()
系統調用禁止/啟用系統記錄進程信息。若file為NULL,記錄功能將被禁用;
若file指向一個存在的檔案(以'\0'結尾),則記錄功能被啟用,
正常結束的進程都會在該檔案尾添加對應的信息。異常結束是指重啟或其它致命的系統問題。
acct()不能生成那些永遠不會結束的進程的信息。
關於acct()使用的記錄結構及其它相關信息,請參閱<sys/acct.h>及acct(5)。
筆記:
當
記錄檔案所在的檔案系統空間已滿時,記錄功能將被自動禁用;當空間足夠時,
它會被自動啟用。自動行為可以通過sysctl(8)修改對應的變數來控制:
kern.acct_chkfreq 指定檢查剩餘空間大小的頻率(秒)
kern.acct_resume 剩餘空間高於該百分比時,將恢復記錄功能
kern.acct_suspend 剩餘空間低於該百分比時,將暫停記錄功能
返回值:
有錯誤時返回-1。file檔案必須存在且只能由
超級用戶調用。
錯誤:
acct()失敗時將設定errno為下列錯誤常量:
[EPERM] 調用者不是超級用戶
[ENOTDIR] file中的某目錄組分不是目錄
[ENAMETOOLONG] file中的某目錄組分超過255位元組或file超過1023位元組
[ENOENT] 檔案不存在
[EACCES] file中某目錄組分不允許搜尋或file不是一個普通檔案
[EROFS] 試圖在唯讀檔案系統上請求寫操作
[ETXTBSY] 試圖對執行中的檔案請求寫操作
[EFAULT] file參數指向的地址超出了進程的存取空間
[EIO] 讀/寫檔案系統時遇到了I/O錯誤
歷史:
acct()
系統調用在AT&T UNIX版本7里首次出現。
(2)ACCT :ACCOUNT 帳目,帳戶 (在外貿中常用到這個縮寫)