📄 time.texi
字号:
@comment BSD@item RUSAGE_SELFJust the current process.@comment sys/resource.h@comment BSD@item RUSAGE_CHILDRENAll child processes (direct and indirect) that have terminated already.@end tableIn the GNU system, you can also inquire about a particular child processby specifying its process ID.The return value of @code{getrusage} is zero for success, and @code{-1}for failure.@table @code@item EINVALThe argument @var{processes} is not valid.@end table@end deftypefunOne way of getting usage figures for a particular child process is withthe function @code{wait4}, which returns totals for a child when itterminates. @xref{BSD Wait Functions}.@comment sys/resource.h@comment BSD@deftp {Data Type} {struct rusage}This data type records a collection usage amounts for various sorts ofresources. It has the following members, and possibly others:@table @code@item struct timeval ru_utimeTime spent executing user instructions.@item struct timeval ru_stimeTime spent in operating system code on behalf of @var{processes}.@item long int ru_maxrssThe maximum resident set size used, in kilobytes. That is, the maximumnumber of kilobytes that @var{processes} used in real memory simultaneously.@item long int ru_ixrssAn integral value expressed in kilobytes times ticks of execution, whichindicates the amount of memory used by text that was shared with otherprocesses.@item long int ru_idrssAn integral value expressed the same way, which is the amount ofunshared memory used in data.@item long int ru_isrssAn integral value expressed the same way, which is the amount ofunshared memory used in stack space.@item long int ru_minfltThe number of page faults which were serviced without requiring any I/O.@item long int ru_majfltThe number of page faults which were serviced by doing I/O.@item long int ru_nswapThe number of times @var{processes} was swapped entirely out of main memory.@item long int ru_inblockThe number of times the file system had to read from the disk on behalfof @var{processes}.@item long int ru_oublockThe number of times the file system had to write to the disk on behalfof @var{processes}.@item long int ru_msgsndNumber of IPC messages sent.@item long ru_msgrcvNumber of IPC messages received.@item long int ru_nsignalsNumber of signals received.@item long int ru_nvcswThe number of times @var{processes} voluntarily invoked a context switch(usually to wait for some service).@item long int ru_nivcswThe number of times an involuntary context switch took place (becausethe time slice expired, or another process of higher priority becamerunnable).@end table@end deftpAn additional historical function for examining usage figures,@code{vtimes}, is supported but not documented here. It is declared in@file{sys/vtimes.h}.@node Limits on Resources@section Limiting Resource Usage@cindex resource limits@cindex limits on resource usage@cindex usage limitsYou can specify limits for the resource usage of a process. When theprocess tries to exceed a limit, it may get a signal, or the system callby which it tried to do so may fail, depending on the limit. Eachprocess initially inherits its limit values from its parent, but it cansubsequently change them.@pindex sys/resource.hThe symbols in this section are defined in @file{sys/resource.h}.@comment sys/resource.h@comment BSD@deftypefun int getrlimit (int @var{resource}, struct rlimit *@var{rlp})Read the current value and the maximum value of resource @var{resource}and store them in @code{*@var{rlp}}.The return value is @code{0} on success and @code{-1} on failure. Theonly possible @code{errno} error condition is @code{EFAULT}.@end deftypefun@comment sys/resource.h@comment BSD@deftypefun int setrlimit (int @var{resource}, struct rlimit *@var{rlp})Store the current value and the maximum value of resource @var{resource}in @code{*@var{rlp}}.The return value is @code{0} on success and @code{-1} on failure. Thefollowing @code{errno} error condition is possible:@table @code@item EPERMYou tried to change the maximum permissible limit value,but you don't have privileges to do so.@end table@end deftypefun@comment sys/resource.h@comment BSD@deftp {Data Type} {struct rlimit}This structure is used with @code{getrlimit} to receive limit values,and with @code{setrlimit} to specify limit values. It has two fields:@table @code@item rlim_curThe current value of the limit in question.This is also called the ``soft limit''.@cindex soft limit@item rlim_maxThe maximum permissible value of the limit in question. You cannot setthe current value of the limit to a larger number than this maximum.Only the super user can change the maximum permissible value.This is also called the ``hard limit''.@cindex hard limit@end tableIn @code{getrlimit}, the structure is an output; it receives the currentvalues. In @code{setrlimit}, it specifies the new values.@end deftpHere is a list of resources that you can specify a limit for.Those that are sizes are measured in bytes.@table @code@comment sys/resource.h@comment BSD@item RLIMIT_CPU@vindex RLIMIT_CPUThe maximum amount of cpu time the process can use. If it runs forlonger than this, it gets a signal: @code{SIGXCPU}. The value ismeasured in seconds. @xref{Operation Error Signals}.@comment sys/resource.h@comment BSD@item RLIMIT_FSIZE@vindex RLIMIT_FSIZEThe maximum size of file the process can create. Trying to write alarger file causes a signal: @code{SIGXFSZ}. @xref{Operation ErrorSignals}.@comment sys/resource.h@comment BSD@item RLIMIT_DATA@vindex RLIMIT_DATAThe maximum size of data memory for the process. If the process triesto allocate data memory beyond this amount, the allocation functionfails.@comment sys/resource.h@comment BSD@item RLIMIT_STACK@vindex RLIMIT_STACKThe maximum stack size for the process. If the process tries to extendits stack past this size, it gets a @code{SIGSEGV} signal.@xref{Program Error Signals}.@comment sys/resource.h@comment BSD@item RLIMIT_CORE@vindex RLIMIT_COREThe maximum size core file that this process can create. If the processterminates and would dump a core file larger than this maximum size,then no core file is created. So setting this limit to zero preventscore files from ever being created.@comment sys/resource.h@comment BSD@item RLIMIT_RSS@vindex RLIMIT_RSSThe maximum amount of physical memory that this process should get.This parameter is a guide for the system's scheduler and memoryallocator; the system may give the process more memory when there is asurplus.@comment sys/resource.h@comment BSD@item RLIMIT_MEMLOCKThe maximum amount of memory that can be locked into physical memory (soit will never be paged out).@comment sys/resource.h@comment BSD@item RLIMIT_NPROCThe maximum number of processes that can be created with the same user ID.If you have reached the limit for your user ID, @code{fork} will failwith @code{EAGAIN}. @xref{Creating a Process}.@comment sys/resource.h@comment BSD@item RLIMIT_NOFILE@vindex RLIMIT_NOFILE@itemx RLIMIT_OFILE@vindex RLIMIT_OFILEThe maximum number of files that the process can open. If it tries toopen more files than this, it gets error code @code{EMFILE}.@xref{Error Codes}. Not all systems support this limit; GNU does, and4.4 BSD does.@comment sys/resource.h@comment BSD@item RLIM_NLIMITS@vindex RLIM_NLIMITSThe number of different resource limits. Any valid @var{resource}operand must be less than @code{RLIM_NLIMITS}.@end table@comment sys/resource.h@comment BSD@defvr Constant int RLIM_INFINITYThis constant stands for a value of ``infinity'' when supplied asthe limit value in @code{setrlimit}.@end defvr@c ??? Someone want to finish these?Two historical functions for setting resource limits, @code{ulimit} and@code{vlimit}, are not documented here. The latter is declared in@file{sys/vlimit.h} and comes from BSD.@node Priority@section Process Priority@cindex process priority@cindex priority of a process@pindex sys/resource.hWhen several processes try to run, their respective priorities determinewhat share of the CPU each process gets. This section describes how youcan read and set the priority of a process. All these functions andmacros are declared in @file{sys/resource.h}.The range of valid priority values depends on the operating system, buttypically it runs from @code{-20} to @code{20}. A lower priority valuemeans the process runs more often. These constants describe the range ofpriority values:@table @code@comment sys/resource.h@comment BSD@item PRIO_MIN@vindex PRIO_MINThe smallest valid priority value.@comment sys/resource.h@comment BSD@item PRIO_MAX@vindex PRIO_MAXThe smallest valid priority value.@end table@comment sys/resource.h@comment BSD@deftypefun int getpriority (int @var{class}, int @var{id})Read the priority of a class of processes; @var{class} and @var{id}specify which ones (see below). If the processes specified do not allhave the same priority, this returns the smallest value that any of themhas.The return value is the priority value on success, and @code{-1} onfailure. The following @code{errno} error condition are possible forthis function:@table @code@item ESRCHThe combination of @var{class} and @var{id} does not match any existingprocess.@item EINVALThe value of @var{class} is not valid.@end tableWhen the return value is @code{-1}, it could indicate failure, or itcould be the priority value. The only way to make certain is to set@code{errno = 0} before calling @code{getpriority}, then use @code{errno!= 0} afterward as the criterion for failure.@end deftypefun@comment sys/resource.h@comment BSD@deftypefun int setpriority (int @var{class}, int @var{id}, int @var{priority})Set the priority of a class of processes to @var{priority}; @var{class}and @var{id} specify which ones (see below).The return value is @code{0} on success and @code{-1} on failure. Thefollowing @code{errno} error condition are defined for this function:@table @code@item ESRCHThe combination of @var{class} and @var{id} does not match any existingprocess.@item EINVALThe value of @var{class} is not valid.@item EPERMYou tried to set the priority of some other user's process, and youdon't have privileges for that.@item EACCESYou tried to lower the priority of a process, and you don't haveprivileges for that.@end table@end deftypefunThe arguments @var{class} and @var{id} together specify a set ofprocesses you are interested in. These are the possible values for@var{class}:@table @code@comment sys/resource.h@comment BSD@item PRIO_PROCESS@vindex PRIO_PROCESSRead or set the priority of one process. The argument @var{id} is aprocess ID.@comment sys/resource.h@comment BSD@item PRIO_PGRP@vindex PRIO_PGRPRead or set the priority of one process group. The argument @var{id} isa process group ID.@comment sys/resource.h@comment BSD@item PRIO_USER@vindex PRIO_USERRead or set the priority of one user's processes. The argument @var{id}is a user ID.@end tableIf the argument @var{id} is 0, it stands for the current process,current process group, or the current user, according to @var{class}.@c ??? I don't know where we should say this comes from.@comment Unix@comment dunno.h@deftypefun int nice (int @var{increment})Increment the priority of the current process by @var{increment}.The return value is the same as for @code{setpriority}.Here is an equivalent definition for @code{nice}:@smallexampleintnice (int increment)@{ int old = getpriority (PRIO_PROCESS, 0); return setpriority (PRIO_PROCESS, 0, old + increment);@}@end smallexample@end deftypefun
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -