This function is used to return an object used by current process or its children. It returns different fields. From the fields of return value, we can get information about how resource has been used.
This method is used to return number of bytes in a system page. It may not be same as the physical page size.
here are some contants related to resource usage:
It helps to request resources consumed by calling process. It is sum of the all resources of different threads.
It helps to request resources consumed by the child process.
It helps to request resources consumed by calling process as well as the child process. It is not available for all systems
Resource usage by the current thread. It is not available for all systems
here is an example code:
resLimits = resource.getrusage(resource.RUSAGE_SELF)
print('Page Size: ' + str(resource.getpagesize()))
resource.setrlimit(resource.RLIMIT_CPU, (1, 2))
print('Resouce Limits: ' + str(resource.getrlimit(resource.RLIMIT_CPU)))
for i in range(1000):
for j in range(1000):
for k in range(1000):
resource.struct_rusage(ru_utime=0.035801, ru_stime=0.01074, ru_maxrss=9356, ru_ixrss=0, ru_idrss=0,
ru_isrss=0, ru_minflt=1147, ru_majflt=0, ru_nswap=0, ru_inblock=0, ru_oublock=0,
ru_msgsnd=0, ru_msgrcv=0, ru_nsignals=0, ru_nvcsw=0, ru_nivcsw=17)
Page Size: 4096
Resouce Limits: (1, 2)
CPU time limit exceeded (core dumped)