- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试使用 cgroups 来停止实际使用过多内存的程序,同时让它们运行,如果它们只是分配而不实际使用大量内存。但是,它似乎不起作用;有什么建议么?在 Ubuntu 机器上,我按如下方式设置我的 cgroup[1]:
#Changing $USER to a system user running the process
sudo apt-get install cgroup-bin
sudo cgcreate -a $USER -g memory:$USER
echo 100M > /cgroup/memory/$USER/memory.limit_in_bytes
#Running the program using cgroups
cgexec -g memory:$USER program
我正在使用以下程序(回答“否”应该有效,而"is"应该停止)。
#include <stdlib.h>
#include <stdio.h>
#define SIZE (long int) 1*1024*1024*1024*sizeof(char)/*1 GB*/
int main(void)
{
char *str = (char*) malloc(SIZE);
char *ans = (char*) malloc(100);
printf("Write random values to memory? (yes/no): ");
scanf("%s", ans);
if (strcmp(ans,"yes") == 0) {
FILE *f = fopen("/dev/urandom","r");
fread(str,1,SIZE,f);
printf("Success!!\n");
fclose(f);
free(str);
}
else {
printf("Have a good day!\n");
}
return(0);
}
最佳答案
您的测试返回成功,因为它没有检查错误。事实上,当您的二进制文件达到内存限制时, fread 调用分配失败。您可以通过更改代码来检查错误来看到这一点:
#include <stdlib.h>
#include <stdio.h>
#define SIZE (long int) 1*1024*1024*1024*sizeof(char)/*1 GB*/
int main(void)
{
char *str = (char*) malloc(SIZE);
char *ans = (char*) malloc(100);
printf("Write random values to memory? (yes/no): ");
scanf("%s", ans);
if (strcmp(ans,"yes") == 0) {
FILE *f = fopen("/dev/urandom","r");
int size = fread(str,1,SIZE,f);
if (size < SIZE) {
printf("incomplete read: %d, error %d\n", size, ferror(f));
} else {
printf("Success!!\n");
}
fclose(f);
free(str);
}
else {
printf("Have a good day!\n");
}
return(0);
}
更酷的是使用 cgroup 监控实用程序,如 cadvisor您可以以图形方式看到您的二进制文件达到了极限。 .希望有所帮助:)
关于linux - 在 Linux 上使用 cgroups 控制内存使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28843537/
我在 上做了以下两件事Ubuntu 14 和 SUSE Linux Enterprise Server 11 (x86_64) 安装 libcgroup 的地方,使用 root: cgcreate -
我是 cgroup 的新手。我想使用 cgroup 将 Qemu 绑定(bind)到某些 CPU。我正在使用我自己编译的内核 3.11.0+ 在 Ubuntu 12.04.3 上工作。 以下是我的命令
昨天我在 cgroups 内存 Controller 上遇到了一个有趣的情况。我一直认为cgroups报告的内存是进程的总内存消耗,但似乎不是这样。 我编写了以下 Java 程序用于测试: impor
我们使用cgroup限制程序使用更多资源。但是,当内存超过 cgroup 的限制时,它会杀死进程。为什么 cgroup 的内存子系统在进程允许内存超过 cgroup 限制时使用 oom-killer
我已经配置了如下的logstash配置来读取spring boot生成的日志以推送到 Elasticsearch ,但是即使logstash成功启动也没有创建索引, 配置文件: input {
cgroup driver的配置在/etc/systemd/system/kubelet.service.d/10-kubeadm.conf Environment="KUBELET_CGROUP_A
我是 docker 新手,我插入我的 PI3 来测试一些东西,但我已经面临一个错误,我自己想不通。 所以我全新安装了 raspbian 和 docker。 这是我的安装日志 然后我尝试经典的 hell
前言 docker 使用cgrqup控制资源,K8S 里面也有limit(使用上限) docker通过cgroup来控制容器使用的资源配额,包括CPU、内存、磁盘三大方面,基本覆盖了常见的资源配额和使
我试图在kubernetes机器中设置centos,kubelets启动给了我这个错误。 Failed to get kubelets cgroup: cpu and memory cgroup hi
我正在测试 mesos cgroups 隔离。查看抛出什么样的错误。我用马拉松跑了下面的 shell 程序。已分配 1 MB 内存和 1 个 CPU。 #!/bin/sh temp=a while
我最近开始学习 docker,似乎大部分繁重的工作都是由 Linux 内核完成的,使用命名空间和 cgroup。 我发现一些令人困惑的事情是: 命名空间和 cgroup 有什么区别?他们解决了哪些不同
docker cgroup 资源监控的详解 1.cgroup术语解析: ?
我试图通过使用cgroup blkio Controller 来控制I/O 带宽。 Cgroup 已成功设置和挂载,即调用 grep cgroup/proc/mounts 返回: .... cgrou
如果我运行这个命令: su -l otheruser -c 'strace /usr/lib/systemd/systemd --user 2> /tmp/su.err' 失败了: Failed to
我知道如何使用 cgroups(分配内存、cpu 使用...)和 slurm(提交、暂停/停止工作)。我想知道 cgroups 如何与 slurm 一起工作。当我向 slurm 提交作业时,我可以在哪
我正在寻找编写一个自定义的 Mesos 执行器,它允许为我的 Rails 应用程序请求 1CPU(1024 个共享),然后在前面“插入”nginx。在这个过程中,我实际上想使用相同的共享 1024 c
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 7 年前。 Improve
我有一些 cgroups 管理的服务(实际上在 docker 中运行)。为了公平地安排一些需要资源的任务,容器化服务需要知道它的确切(尽可能)资源使用情况。我决定从 cgroups 中读取这些指标。
基本上,通常用于通知文件系统更改的 inotify 在 cgroup 虚拟文件系统中不起作用。 本质上,我想要一种在 cgroup 中的进程死亡或 fork 时获得类似于 inotify 的通知的方法
我试图理解 Hadoop 中的 cgroups,但无法完全理解。它们与根据配置规则为每个队列分配资源的调度程序有何不同?我的理解是,调度程序似乎更多地与内存相关,因为组与 CPU 相关。我的理解正确吗
我是一名优秀的程序员,十分优秀!