-->
Page 767
In addition to these errors, setpriority will fail with the following:
EPERM | A process was located, but neither its effective nor real user ID matched the effective user ID of the caller. |
EACCES | A nonsuperuser attempted to lower a process priority. |
HISTORY
These function calls appeared in BSD 4.2.
SEE ALSO
nice(1), fork(2), renice(8)
BSD Man Page, 24 July 1993
getrlimit, getrusage, setrlimitGet/set resource limits and usage
SYNOPSIS
#include <sys/time.h> #include <sys/resource.h> #include <unistd.h> int getrlimit (int resource, struct rlimit *rlim); int getrusage (int who, struct rusage *usage); int setrlimit (int resource, const struct rlimit *rlim);
DESCRIPTION
getrlimit and setrlimit get and set resource limits. resource should be one of the following:
RLIMIT CPU /* CPU time in seconds */ RLIMIT FSIZE /* Maximum filesize */ RLIMIT DATA /* max data size */ RLIMIT STACK /* max stack size */ RLIMIT CORE /* max core file size */ RLIMIT RSS /* max resident set size */ RLIMIT NPROC /* max number of processes */ RLIMIT NOFILE /* max number of open files */ RLIMIT MEMLOCK /* max locked-in-memory address space*/
A resource may be unlimited if you set the limit to RLIM_INFINITY. RLIMIT_OFILE is the BSD name for RLIMIT_NOFILE.
The rlimit structure is defined as follows :
struct rlimit { int rlim_cur; int rlim_max; };
getrusage returns the current resource usages for a who of either RUSAGE_SELF or RUSAGE_CHILDREN:
struct rusage { struct timeval ru_utime; /* user time used */ struct timeval ru_stime; /* system time used */ long ru_maxrss; /* maximum resident set size */ long ru_ixrss; /* integral shared memory size */
Page 768
long ru_idrss; /* integral unshared data size */ long ru_isrss; /* integral unshared stack size */ long ru_minflt; /* page reclaims */ long ru_majflt; /* page faults */ long ru_nswap; /* swaps */ long ru_inblock; /* block input operations */ long ru_oublock; /* block output operations */ long ru_msgsnd; /* messages sent */ long ru_msgrcv; /* messages received */ long ru_nsignals; /* signals received */ long ru_nvcsw; /* voluntary context switches */ long ru_nivcsw; /* involuntary context switches */ };
RETURN VALUE
On success, 0 is returned. On error, _1 is returned and errno is set appropriately.
ERRORS
EINVAL | getrlimit or setrlimit is called with a bad resource. getrusage is called with a bad who. |
EPERM | A nonsuperuser tries to use setrlimit() to increase the soft or hard limit above the current hard limit, or a superuser tries to increase RLIMIT_NOFILE above the current kernel maximum. |
CONFORMS TO
BSD 4.3
SEE ALSO
ulimit(2), quota(2)
Linux, 23 July 1993
getsidGets session ID
SYNOPSIS
#include <unistd.h> pid_t getsid(void);
DESCRIPTION
getsid(0) returns the session ID of the calling process. getsid(p) returns the session ID of the process with process ID p.
ERRORS
On error, _1 will be returned. The only error that can happen is ESRCH, when no process with process ID p was found.
CONFORMS TO
This call is Linux specific.
SEE ALSO
setsid(2)
Linux 1.3.85, 11 April 1996
Page 769
getsockopt, setsockopt
getsocknameGets socket name
SYNOPSIS
int getsockname(int s ", struct sockaddr *" name ", int *" namelen );
DESCRIPTION
getsockname returns the current name for the specified socket. The namelen parameter should be initialized to indicate the amount of space pointed to by name. On return it contains the actual size of the name returned (in bytes).
RETURN VALUE
On success, 0 is returned. On error, _1 is returned and errno is set appropriately.
ERRORS
EBADF | The argument s is not a valid descriptor. |
ENOTSOCK | The argument s is a file, not a socket. |
ENOBUFS | Insufficient resources were available in the system to perform the operation. |
EFAULT | The name parameter points to memory not in a valid part of the process address space. |
HISTORY
The getsockname function call appeared in BSD 4.2.
BUGS
Names bound to sockets in the UNIX domain are inaccessible; getsockname returns a 0-length name.
SEE ALSO
bind(2), socket(2)
BSD Man Page, 24 July 1993
getsockopt, setsockoptGet and set options on sockets
SYNOPSIS
#include <sys/types.h> #include <sys/socket.h> int getsockopt(int s,intlevel,intoptname,void*optval,int*optlen); int setsockopt(int s,intlevel,intoptname, const void *optval,intoptlen);
DESCRIPTION
getsockopt and setsockopt manipulate the options associated with a socket. Options may exist at multiple protocol levels; they are always present at the uppermost socket level.
When manipulating socket options, the level at which the option resides and the name of the option must be specified. To manipulate options at the socket level, level is specified as SOL_SOCKET. To manipulate options at any other level, the protocol number of the appropriate protocol controlling the option is supplied. For example, to indicate that an option is to be interpreted by the TCP protocol, level should be set to the protocol number of TCP; see getprotoent(3).
Page 770
The parameters optval and optlen are used to access option values for setsockopt. For getsockopt they identify a buffer in which the value for the requested option(s) is to be returned. For getsockopt, optlen is a value-result parameter, initially containing the size of the buffer pointed to by optval, and modified on return to indicate the actual size of the value returned. If no option value is to be supplied or returned, optval may be NULL.
optname and any specified options are passed uninterpreted to the appropriate protocol module for interpretation. The include file <sys/socket.h> contains definitions for socket-level options, described below. Options at other protocol levels vary in format and name; consult the appropriate entries in section 4 of the manual.
Most socket-level options utilize an int parameter for optval. For setsockopt, the parameter should be nonzero to enable a boolean option, or 0 if the option is to be disabled. SO_LINGER uses a struct linger parameter, defined in <linux/socket.h>, which specifies the desired state of the option and the linger interval (see below). SO_SNDTIMEO and SO_RCVTIMEO use a struct timeval parameter, defined in <sys/time.h>.
The following options are recognized at the socket level. Except as noted, each may be examined with getsockopt and set with setsockopt:
SO_DEBUG | Enables recording of debugging information. |
SO_REUSEADDR | Enables local address reuse. |
SO_KEEPALIVE | Enables keep connections alive. |
SO_DONTROUTE | Enables routing bypass for outgoing messages. |
SO_LINGER | Linger on close if data present. |
SO_BROADCAST | Enables permission to transmit broadcast messages. |
SO_OOBINLINE | Enables reception of out-of-band data in band. |
SO_SNDBUF | Sets buffer size for output. |
SO_RCVBUF | Sets buffer size for input. |
SO_SNDLOWAT | Sets minimum count for output. |
SO_RCVLOWAT | Sets minimum count for input. |
SO_SNDTIMEO | Sets time-out value for output. |
SO_RCVTIMEO | Sets time-out value for input. |
SO_TYPE | Gets the type of the socket (get only). |
SO_ERROR | Gets and clears error on the socket (get only). |
SO_DEBUG enables debugging in the underlying protocol modules.
SO_REUSEADDR indicates that the rules used in validating addresses supplied in a bind(2) call should allow reuse of local addresses.
SO_KEEPALIVE enables the periodic transmission of messages on a connected socket. Should the connected party fail to respond to these messages, the connection is considered broken and processes using the socket are notified via a SIGPIPE signal when attempting to send data.
SO_DONTROUTE indicates that outgoing messages should bypass the standard routing facilities. Instead, messages are directed to the appropriate network interface according to the network portion of the destination address.
SO_LINGER controls the action taken when unsent messages are queued on socket and a close(2) is performed. If the socket promises reliable delivery of data and SO_LINGER is set, the system will block the process on the close attempt until it is able to transmit the data or until it decides it is unable to deliver the information (a time-out period, termed the linger interval, is specified in the setsockopt call when SO_LINGER is requested). If SO_LINGER is disabled and a close is issued, the system will process the close in a manner that allows the process to continue as quickly as possible.
The linger structure is defined in <linux/socket.h> as follows:
struct linger { int l_onoff; /* Linger active */ int l_linger; /* How long to linger for */ };