Mihai Sprinceana
Un forum de programare cu de toate. Va astept sa va inscrieti si sa deveniti moderatori. Oricine este binevenit aici sa se inscrie si sa aiba acces la informatie free! Fiecare este liber sa adauge proiecte programe free etc. Ajutati acest forum sa devina o comunitate puternica unde fiecare invata de la fiecare! Tot ce trebuie sa faceti este sa va inregistrati si fiecare contributie se poate dovedi utila in timp! Forumul este free informatia free dk aveti timp liber ajutati si pe ceilalti si invatati si voi in acelasi timp! Haideti sa facem ceva pt.a ne ajuta intre noi! Cititi regulament postare forum inainte de a posta!
Lista Forumurilor Pe Tematici
Mihai Sprinceana | Inregistrare | Login

POZE MIHAI SPRINCEANA

Nu sunteti logat.
Nou pe simpatie:
Anna281
Femeie
25 ani
Iasi
cauta Barbat
25 - 44 ani
Mihai Sprinceana / SO Linux&Unix / Functiile getrlimit,getrusage,setrlimit (apeluri sistem) Moderat de Cristy89, Houssey, cr3us, fireratbat, profu.info, sade5000
Autor
Mesaj Pagini: 1
Cristy89
Moderator

Inregistrat: acum 15 ani
Postari: 26
getrlimit, getrusage, setrlimit - preia/seteaza folosirea si limitarea resurselor

Trebuie sa aveti incluse fisierele biblioteca(header):

#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>


Forma generala:

int getrlimit(int resource, struct rlimit *rlim);
int getrusage(int who, struct rusage *usage);
int setrlimit(int resource, const struct rlimit *rlim); 

Fiecare resursa are asociata o limita hard sau soft , definita de structura rlimit (argumentul rlim este folosit la ambele apeluri sistem getrlimit() respectiv setrlimit() )

Mai jos avem definita structura rlimit:

struct rlimit {
    rlim_t rlim_cur;   /* Soft limit */
    rlim_t rlim_max;   /* Hard limit (ceiling
                          for rlim_cur) */
};

Limita soft este valoarea pe care kernel-ul(nucleul sistemului de operare) o forteaza pt.resursa corespunzatoare.

Limita hard este un plafon pt.limita soft; un proces neprivilegiat isi poate seta doar limita soft la o valoare intre 0 pana la limita hard. Un proces privilegiat isi poate schimba valoarei limitei la o valoare arbitrara.

Valoarea RLIM_INFINITY denota lipsa unei limite a unei resurse(intoarsa in structura de getrlimit() si din structura trecuta la setrlimit() )



Resursa poate fi una din tipurile:


RLIMIT_AS
    The maximum size of the process's virtual memory (address space) in bytes. This limit affects calls to brk(2), mmap(2) and mremap(2), which fail with the error ENOMEM upon exceeding this limit. Also automatic stack expansion will fail (and generate a SIGSEGV that kills the process when no alternate stack has been made available). Since the value is a long, on machines with a 32-bit long either this limit is at most 2 GiB, or this resource is unlimited.
RLIMIT_CORE
    Maximum size of core file. When 0 no core dump files are created. When nonzero, larger dumps are truncated to this size.
RLIMIT_CPU
    CPU time limit in seconds. When the process reaches the soft limit, it is sent a SIGXCPU signal. The default action for this signal is to terminate the process. However, the signal can be caught, and the handler can return control to the main program. If the process continues to consume CPU time, it will be sent SIGXCPU once per second until the hard limit is reached, at which time it is sent SIGKILL. (This latter point describes Linux 2.2 and 2.4 behaviour. Implementations vary in how they treat processes which continue to consume CPU time after reaching the soft limit. Portable applications that need to catch this signal should perform an orderly termination upon first receipt of SIGXCPU.)
RLIMIT_DATA
    The maximum size of the process's data segment (initialized data, uninitialized data, and heap). This limit affects calls to brk() and sbrk(), which fail with the error ENOMEM upon encountering the soft limit of this resource.
RLIMIT_FSIZE
    The maximum size of files that the process may create. Attempts to extend a file beyond this limit result in delivery of a SIGXFSZ signal. By default, this signal terminates a process, but a process can catch this signal instead, in which case the relevant system call (e.g., write(), truncate()) fails with the error EFBIG.
RLIMIT_LOCKS
    A limit on the combined number of flock() locks and fcntl() leases that this process may establish. (Early Linux 2.4 only.)
RLIMIT_MEMLOCK
    The maximum number of bytes of virtual memory that may be locked into RAM using mlock() and mlockall().
RLIMIT_NOFILE
    Specifies a value one greater than the maximum file descriptor number that can be opened by this process. Attempts (open(), pipe(), dup(), etc.) to exceed this limit yield the error EMFILE.
RLIMIT_NPROC
    The maximum number of processes that can be created for the real user ID of the calling process. Upon encountering this limit, fork() fails with the error EAGAIN.
RLIMIT_RSS
    Specifies the limit (in pages) of the process's resident set (the number of virtual pages resident in RAM). This limit only has effect in Linux 2.4 onwatrds, and there only affects calls to madvise() specifying MADVISE_WILLNEED.
RLIMIT_STACK
    The maximum size of the process stack, in bytes. Upon reaching this limit, a SIGSEGV signal is generated. To handle this signal, a process must employ an alternate signal stack (sigaltstack(2)).

RLIMIT_OFILE is the BSD name for RLIMIT_NOFILE.

Getrusage intoarce folosirea resursei curenta pt. un anumit tip de resursa RUSAGE_SELF sau RUSAGE_CHILDREN.
getrusage returns the current resource usages, for a who of either RUSAGE_SELF or RUSAGE_CHILDREN.
Practic se vor cele detalii pt.resursele folosite de procesul curent si apoi la sfarsit resursele folosite de procesele copil(fiu) ale procesului curent(parinte).

Mai jos aveti definita structura rusage:



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 */
    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 */
};

In caz de succes valoarea 0 este intoarsa. In caz de eroare intoarce mesaj de eroare sau este setat un mesaj de eroare corespunzator folosind errno.


ERRORS

EFAULT -rlim sau folosirea punctelor resurselor in afara spatiului de adresare accesibil


EINVAL - getrlimit sau setrlimt este apelata cu o resursa gresita sau getrusage este apelata cu o instructiune who gresita

EPERM - un utilizator de tip non-superuser incearca sa foloseasca setrlimit() pt. a creste limita soft sau hard a limitei curent a hard-ului, sau un utilizator super-user incearca sa creasca RLIMIT_NOFILE in cadrul kernel-ului (nucleului SO) la maximum


pus acum 15 ani
   
Pagini: 1  

Mergi la