Download CS 3100

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

DNIX wikipedia , lookup

Process management (computing) wikipedia , lookup

Transcript
CS 3100
Operating Systems
Spring 2002
Unix time management and timers
GETTIMEOFDAY(2)
Linux Programmer's Manual
GETTIMEOFDAY(2)
NAME
gettimeofday, settimeofday
- get / set time
SYNOPSIS
#include <sys/time.h>
int gettimeofday(struct timeval *tv, struct timezone *tz);
int settimeofday(const struct timeval *tv , const struct
timezone *tz);
DESCRIPTION
gettimeofday and settimeofday can set the time as well as
a timezone. tv is a timeval struct, as specified
in
/usr/include/sys/time.h:
struct timeval {
long tv_sec;
long tv_usec;
};
/* seconds */
/* microseconds */
and tz is a timezone :
struct timezone {
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime;
/* type of dst correction */
};
The use of the timezone struct is obsolete; the tz_dsttime
field has never been used under Linux
...
RETURN VALUE
gettimeofday and settimeofday return 0 for success, or -1
for failure (in which case errno is set appropriately).
ERRORS
EPERM
settimeofday
superuser.
is called by someone other than the
EINVAL Timezone (or something else) is invalid.
EFAULT One of tv or tz
address space.
pointed outside your
accessible
CONFORMING TO
SVr4, BSD 4.3
SEE ALSO
date(1), adjtimex(2), time(2), ctime(3), ftime(3)
840960637
05/01/17
CS 3100
GETITIMER(2)
Operating Systems
Spring 2002
Linux Programmer's Manual
GETITIMER(2)
NAME
getitimer,
timer
setitimer
-
get
or set value of an interval
SYNOPSIS
#include <sys/time.h>
int getitimer(int which, struct itimerval *value);
int setitimer(int which, const struct itimerval *value,
struct itimerval *ovalue);
DESCRIPTION
The system provides each process with three interval
timers, each decrementing in a distinct time domain. When
any timer expires, a signal is sent to the process, and
the timer (potentially) restarts.
ITIMER_REAL
decrements in real
SIGALRM upon expiration.
time,
and
delivers
ITIMER_VIRTUAL decrements only when the process is execut
ing, and delivers SIGVTALRM upon expira
tion.
ITIMER_PROF
decrements both
when the process executes
and when the system is executing on behalf
of the process. Coupled with ITIMER_VIR
TUAL, this timer is usually used to profile
the time
spent by the application in user
and kernel space.
SIGPROF is
delivered
upon expiration.
Timer values are defined by the following structures:
struct itimerval {
struct timeval it_interval; /* next value */
struct timeval it_value;
/* current value */
};
struct timeval {
long tv_sec;
/* seconds */
long tv_usec;
/* microseconds */
};
Getitimer(2) fills the structure indicated by value with
the current setting for the timer indicated by which (one
of ITIMER_REAL, ITIMER_VIRTUAL, or ITIMER_PROF).
The ele
ment it_value is set to the amount of time remaining on
the timer, or zero if the timer is disabled. Similarly,
it_interval is set to the reset value. Setitimer(2) sets
the indicated timer to the value in value. If ovalue is
nonzero, the old value of the timer is stored there.
Timers decrement from it_value to zero, generate a signal,
and reset to it_interval. A timer which is set to zero
(it_value is zero or the timer expires and it_interval is
GETITIMER(2)
840960637
Linux Programmer's Manual
GETITIMER(2)
05/01/17
CS 3100
Operating Systems
Spring 2002
zero) stops.
Both tv_sec and tv_usec are significant in determining the
duration of a timer.
Timers will never expire before the requested time,
instead
expiring some
short, constant time afterwards,
dependent on the system timer resolution (currently 10ms).
Upon expiration, a signal will be generated and the timer
reset. If the timer expires while the process is active
(always true for ITIMER_VIRT) the signal will be delivered
immediately when generated. Otherwise the delivery will
be offset by a small time dependent on the system loading.
RETURN VALUE
On success, zero is returned. On error, -1
and errno is set appropriately.
is
returned,
ERRORS
EFAULT value or ovalue are not valid pointers.
EINVAL which is not
ITIMER_PROF.
one of ITIMER_REAL, ITIMER_VIRT, or
CONFORMING TO
SVr4, 4.4BSD (This call first appeared in 4.2BSD).
SEE ALSO
gettimeofday(2), sigaction(2), signal(2).
BUGS
Under Linux, the generation and delivery of a signal are
distinct, and there each signal is permitted only one out
standing event. It's therefore conceivable that under
pathologically heavy loading,
ITIMER_REAL will expire
before the signal from a previous expiration has been
delivered.
The second signal in such an event will be
lost.
840960637
05/01/17
CS 3100
SIGNAL(2)
Operating Systems
Linux Programmer's Manual
Spring 2002
SIGNAL(2)
NAME
signal - ANSI C signal handling
SYNOPSIS
#include <signal.h>
void (*signal(int signum, void (*sighandler)(int)))(int);
DESCRIPTION
The signal() system call installs a new signal handler for
the signal with number signum. The signal handler is set
to sighandler which may be a user specified function, or
either SIG_IGN or SIG_DFL.
Upon arrival of a signal with number signum the
following
happens.
If the corresponding handler is set to SIG_IGN,
then the signal is ignored. If
the handler is set to
SIG_DFL,
then the default action associated to the signal
(see signal(7)) occurs. Finally, if the handler is set to
a function sighandler then first either the handler is
reset to SIG_DFL or an implementation-dependent blocking
of the
signal is performed and next sighandler is called
with argument signum.
Using a signal handler function for a signal is called
"catching the signal". The signals SIGKILL and SIGSTOP
cannot be caught or ignored.
RETURN VALUE
The function signal() returns the previous
signal handler, or SIG_ERR on error.
value
of
the
CONFORMING TO
ANSI C
SEE ALSO
kill(1), kill(2), killpg(2), pause(2), raise(3), sigac
tion(2), signal(7), sigsetops(3), sigvec(2), alarm(2)
840960637
05/01/17
CS 3100
KILL(2)
Operating Systems
Spring 2002
Linux Programmer's Manual
KILL(2)
NAME
kill - send signal to a process
SYNOPSIS
#include <sys/types.h>
#include <signal.h>
int kill(pid_t pid, int sig);
DESCRIPTION
The kill system call can be used to send any signal to any
process group or process.
If pid is positive, then signal sig is sent to pid.
If pid equals 0, then sig is sent to every process in
process group of the current process.
the
If pid equals -1, then sig is sent to every process except
for the first one.
If pid is less than -1, then sig is sent to every
in the process group -pid.
process
If sig is 0, then no signal is sent, but error checking is
still performed.
RETURN VALUE
On success, zero is returned. On error, -1
and errno is set appropriately.
is
returned,
ERRORS
EINVAL An invalid signal was specified.
ESRCH
The pid or process group does not exist.
Note that
an existing process might be a zombie, a process
which already committed
termination, but has not
yet been wait()ed for.
EPERM
The process does not have permission to
send the
signal to any of the receiving processes. For a
process to have permission to send a signal to pro
cess pid
it must either have root privileges, or
the real or effective user ID of the sending pro
cess must equal the real or saved set-user-ID of
the receiving process. In the case of SIGCONT it
suffices
when the sending and receiving processes
belong to the same session.
CONFORMING TO
SVr4, SVID, POSIX.1, X/OPEN, BSD 4.3
SEE ALSO
_exit(2), exit(3), signal(2), signal(7)
840960637
05/01/17
CS 3100
Operating Systems
TIME(1)
Spring 2002
TIME(1)
NAME
time - time a simple command or give resource usage
SYNOPSIS
time [options] command [arguments...]
DESCRIPTION
The time command runs the specified program command with
the given arguments. When command finishes, time writes a
message
to standard output giving timing statistics about
this program run. These statistics consist of
(i) the
elapsed real time between invocation and termination, (ii)
the user CPU time (the sum of the tms_utime and tms_cutime
values in a struct tms as returned by times(2)), and (iii)
the system CPU time (the sum of the tms_stime and
tms_cstime
values
in
a struct tms
as returned by
times(2)).
840960637
05/01/17
CS 3100
CTIME(3)
Operating Systems
Spring 2002
Linux Programmer's Manual
CTIME(3)
NAME
asctime,
ctime,
gmtime,
binary date and time to ASCII
localtime,
mktime
- transform
SYNOPSIS
#include <time.h>
char *asctime(const struct tm *timeptr);
char *ctime(const time_t *timep);
struct tm *gmtime(const time_t *timep);
struct tm *localtime(const time_t *timep);
time_t mktime(struct tm *timeptr);
extern char *tzname[2];
long int timezone;
extern int daylight;
DESCRIPTION
The ctime(), gmtime() and localtime() functions
all take
an argument of data type time_t which represents calendar
time. When interpreted as an absolute time value, it rep
resents
the number of seconds elapsed since 00:00:00 on
January 1, 1970, Coordinated Universal Time (UTC).
The asctime() and mktime() functions both take an argument
representing broken-down time which is a binary represen
tation separated into year, month, day, etc.
Broken-down
time is
stored
in the structure tm which is defined in
<time.h> as follows:
struct tm
{
int
int
int
int
int
int
int
int
int
};
tm_sec;
tm_min;
tm_hour;
tm_mday;
tm_mon;
tm_year;
tm_wday;
tm_yday;
tm_isdst;
/*
/*
/*
/*
/*
/*
/*
/*
/*
seconds */
minutes */
hours */
day of the month */
month */
year */
day of the week */
day in the year */
daylight saving time */
The ctime() function converts the calendar time timep into
a string of the form
"Wed Jun 30 21:49:08 1993\n"
The return value points to a statically allocated
string which might be overwritten by subsequent calls to
any of the date and time functions.
840960637
05/01/17
CS 3100
TIME(2)
Operating Systems
Spring 2002
Linux Programmer's Manual
TIME(2)
NAME
time - get time in seconds
SYNOPSIS
#include <time.h>
time_t time(time_t *t);
DESCRIPTION
time returns the time since the Epoch (00:00:00 UTC, Jan
uary 1, 1970), measured in seconds.
If t is non-NULL, the return value is also stored
memory pointed to by t.
in
the
RETURN VALUE
On success, the value of time in seconds since the Epoch
is returned. On error,
((time_t)-1) is returned, and
errno is set appropriately.
ERRORS
EFAULT t points outside your accessible address space.
840960637
05/01/17
CS 3100
TIMES(2)
Operating Systems
Linux Programmer's Manual
Spring 2002
TIMES(2)
NAME
times - get process times
SYNOPSIS
#include <sys/times.h>
clock_t times(struct tms *buf);
DESCRIPTION
The times() function stores the current process times in
the struct tms that buf points to. The struct tms is as
defined in <sys/times.h>:
struct tms {
clock_t
clock_t
clock_t
clock_t
};
tms_utime;
tms_stime;
tms_cutime;
tms_cstime;
/*
/*
/*
/*
user time */
system time */
user time of children */
system time of children */
The tms_utime field contains the CPU time spent executing
instructions of the calling process. The tms_stime field
contains
the CPU time spent in the system while executing
tasks on behalf of the calling process.
The tms_cutime
field contains the sum of the tms_utime and tms_cutime
values for all waited-for terminated children.
The
tms_cstime field contains the
sum of the tms_stime and
tms_cstime values for all waited-for terminated
children.
Times for terminated children (and their descendants) is
added in at the moment wait(2) or waitpid(2) returns their
process ID. In particular, times of grandchildren that the
children did not wait for are never seen.
RETURN VALUE
The function times returns the number of clock ticks that
have elapsed since an arbitrary point in the past.
840960637
05/01/17