Its been on my wish list for a while and I got it working. We might
consider adding a more polished version later to the build system,
as a separate set of packages maybe.
Prereq's
1. Install swig
2. Install python and python-devel is installed
3. Install libcgroup and the devel package
Steps to create the langugage binding
Lets try to create the python binding as an example
1. Create a wrapper script called libcgroup.i with the
following contents
%module libcgroup
%{
#include "libcgroup.h"
%}
#ifdef __cplusplus
# define __BEGIN_DECLS extern "C" {
# define __END_DECLS }
#else
# define __BEGIN_DECLS
# define __END_DECLS
#endif
2. Run gcc -E -nostdinc /usr/include/libcgroup.h >> libcgroup.i
NOTE: Ignore any errors or warnings about missing headers
3. Remove extern __thread int last_errno (swig cannot understand
__thread)
4. Run swig
swig -python libcgroup.i
It'll complain about possible memory leaks (I've ignored them for
now)
You should see two files
a. libcgroup_wrap.c
b. libcgroup.py
5. Run gcc to compile the wrappers
gcc -I /usr/include/python2.6/ -fPIC -shared -o _libcgroup.so
libcgroup_wrap.c -lcgroup
NOTE: Depending on your python version, the include path might vary
6. Now we are ready to test the bindings
a. Test1 (interactive)
python
import libcgroup
help(libcgroup)
b. Mount cgroups and use the API
mount -t cgroup cgroup -o cpu,memory /cgroup
Sample program
from libcgroup import *
cgroup_init()
c = cgroup_new_cgroup("test")
#
# Add the correct controllers based on the mount point
#
cgroup_add_controller(c, "memory")
cgroup_add_controller(c, "cpu")
cgroup_create_cgroup(c, 1)
And there you have it, I hope the language bindings will help you
become more productive and we'll see more contributions to the
library.
--
Three Cheers,
Balbir
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel