I am looking for C specific function to return the container name if it get executed inside the container; Do we have anything of such?
Currently I am trying to get it by reading the file /proc/1/cgroup
@ container:
$> cat /proc/1/cgroup
8:net_cls:/lxc/Container1
7:freezer:/lxc/Container1
6:devices:/lxc/Container1
5:memory:/lxc/Container1
4:cpuacct:/lxc/Container1
3:ns:/Container1
2:debug:/lxc/Container1
1:cpuset:/lxc/Container1
@ Host:
$> cat /proc/1/cgroup
8:net_cls:
7:freezer:
6:devices:
5:memory:
4:cpuacct:
3:ns:
2:debug:
1:cpuset:
With this we can get the container name; here it is "container1" on executing the programm insider the container1 otherwise the function returns "NULL" on executing the same at host.