Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/guicho271828/cl-rlimit

Common lisp interface to unix rlimit -- ensure the performance of your program!
https://github.com/guicho271828/cl-rlimit

Last synced: 29 days ago
JSON representation

Common lisp interface to unix rlimit -- ensure the performance of your program!

Awesome Lists containing this project

README

        

Simple interface to Unix getrlimit and setrlimit.
For further reference see [[http://man7.org/linux/man-pages/man2/setrlimit.2.html][man getrlimit(2)]] and [[http://man7.org/linux/man-pages/man2/getrusage.2.html][man getrusage(2)]].

* rlimit, (setf rlimit)

*function* /rlimit/ resource -> current, max

*function* /(setf rlimit)/ resource size -> size-or-error

/size/ should be an integer.
/resource/ should be one of:

+ =+RLIMIT-ADDRESS-SPACE+= or =+RLIMIT-AS+=
+ =+RLIMIT-CORE+=
+ =+RLIMIT-CPU+= or =+RLIMIT-CPU-TIME+=
+ =+RLIMIT-DATA+=
+ =+RLIMIT-FILE-SIZE+= or =+RLIMIT-FSIZE+=
+ =+RLIMIT-MEMLOCK+=
+ =+RLIMIT-MSGQUEUE+=
+ =+RLIMIT-NICE+=
+ =+RLIMIT-NOFILE+= or + =+RLIMIT-NUMBER-OF-FILES+=
+ =+RLIMIT-NPROC+= or =+RLIMIT-NUMBER-OF-PROCESSES+=
+ =+RLIMIT-OFILE+=
+ =+RLIMIT-REAL-TIME-PRIORITY+=
+ =+RLIMIT-RSS+=
+ =+RLIMIT-RTPRIO+=
+ =+RLIMIT-SIGPENDING+=
+ =+RLIMIT-STACK+=

some of these are synonyms.
To set a limit as infinity, use

+ =+RLIM-INFINITY+=

If the values to be set are inappropriate (exceeds the current limit),
it returns the appropriate errors like =+EFAULT+,+EINVAL+,+EPERM+,+ESRCH+=.

* rusage

(rusage &optional (who =+RUSAGE-SELF+=))

This takes one of =+RUSAGE-SELF+=, =+RUSAGE-CHILDREN+=, =+RUSAGE-THREAD=
and returns a lisp structure =rusage=. =utime= and =stime= is converted
to a full microsecond (combining tv_sec and tv_usec).

#+BEGIN_SRC lisp
(defstruct rusage
(utime 0 :type integer)
(stime 0 :type integer)
(maxrss 0 :type integer)
(ixrss 0 :type integer) ;x on linux
(idrss 0 :type integer) ;x on linux
(isrss 0 :type integer) ;x on linux
(minflt 0 :type integer)
(majflt 0 :type integer)
(nswap 0 :type integer) ;x on linux
(inblock 0 :type integer)
(oublock 0 :type integer)
(msgsnd 0 :type integer) ;x on linux
(msgrcv 0 :type integer) ;x on linux
(nsignals 0 :type integer) ;x on linux
(nvcsw 0 :type integer)
(nivcsw 0 :type integer))
#+END_SRC

* TODOs

+ DONE: further support for =struct rusage=
+ TODO: signal a lisp condition instread of error integers
+ TODO: integration to OSICAT-POSIX

Author: Masataro Asai guicho2.71828-at-gmail-dot-com