int main(int argc, char **argv) { int efd = -1; int cfd = -1; int event_control = -1; char event_control_path[PATH_MAX]; char line[LINE_MAX]; int ret;
if (argc != 3) { fputs(USAGE_STR, stderr); return 1; }
cfd = open(argv[1], O_RDONLY); //要操作的subsystem属性文件 if (cfd == -1) { fprintf(stderr, "Cannot open %s: %s\n", argv[1], strerror(errno)); goto out; }
ret = snprintf(event_control_path, PATH_MAX, "%s/cgroup.event_control", //将参数写到这个配置文件里。内核对此文件的支持很清晰,后面会分析到。 dirname(argv[1])); if (ret >= PATH_MAX) { fputs("Path to cgroup.event_control is too long\n", stderr); goto out; }
event_control = open(event_control_path, O_WRONLY);//打开cgroup event.control配置文件 if (event_control == -1) { fprintf(stderr, "Cannot open %s: %s\n", event_control_path, strerror(errno)); goto out; }