了解bash中的程序使用的内存(在ubuntu linux中) [英] Understanding memory used by a program in bash (in ubuntu linux)

查看:64
本文介绍了了解bash中的程序使用的内存(在ubuntu linux中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些编程比赛中,问题有内存限制(例如64MB或256MB).如何使用bash命令了解我的程序(用C ++编写)使用的内存?有什么方法可以限制程序使用的内存吗?如果程序使用的内存超出限制,则应终止.

解决方案

命令顶部将为您提供所有正在运行的进程以及当前内存和交换的列表,或者如果您希望使用GUI,则可以使用系统监视器应用程序. /p>

对于锁定内存使用量,您始终可以使用ulimit -v设置进程的最大虚拟地址范围.如果malloc及其伙伴尝试获取的内存超过设置的限制,则会导致失败.

In some programming contests, problems have a memory limit (like 64MB or 256MB). How can I understand the memory used by my program (written in C++) with bash commands? Is there any way to limit the memory used by the program? The program should terminate if it uses more memory than the limit.

解决方案

The command top will give you a list of all running processes and the current memory and swap or if you prefer the GUI you can use the System Monitor Application.

As for locking down memory usage you can always use the ulimit -v to set the maximum virtual address range for a process. This will cause malloc and its buddies to fail if they try to get more memory than that set limit.

这篇关于了解bash中的程序使用的内存(在ubuntu linux中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆