进程被操作系统杀死-我所看到的只是控制台上的一条被杀死的消息 [英] Process killed by OS - All I see is a killed message on the console

查看:130
本文介绍了进程被操作系统杀死-我所看到的只是控制台上的一条被杀死的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我要做的就是编写一个实现链接列表的C程序,该程序执行以下操作.

1.通过循环插入从1到100000000的数字.
2.释放程序消耗的内存.

该程序可以在较小的限制下成功运行,但无法在上述范围内运行.

我发现一段时间后我的进程被操作系统杀死.

我在提示符下发出了dmesg命令,并看到以下消息
内存不足:终止进程6881(a.out)".

我了解在32位平台上,一个进程不能消耗超过4GB的内存.这是真的吗?

但是如何知道我的进程是否在执行之前就消耗了超过4GB的内存?
对于我的问题,我想实现一个链表,因为我不知道输入将得到多少数据.

编译器:gcc 4.4.5
操作系统:fedora

需要您的帮助:)

Hi,
All I was trying to do was to write a C program implementing linked list which does the following operations.

1. Inserting numbers from 1 to 100000000 by iterating in a loop.
2. Freeing the consumed memory by the program.

The program runs successfully for smaller limits but fails for the above.

I see that my process is being killed by OS after a while.

I issued dmesg command on the prompt and I see the following message
"Out of memory: Kill process 6881 ( a.out)".

I understand that on a 32 bit platform a process can''t consume more than 4GB of memory. Is this totally true?

But how do I know if my process consumes more than 4GB of memory even before executing it????

For my problem I want to implement a linked list because I do not know how much data I will get as an input.

compiler: gcc 4.4.5
OS: fedora

Need your help :)

推荐答案

32位寻址为2 ^ 32或4GB.

从实际意义上讲,32位应用程序通常限于2 ^ 31或2 GB.
Visual Studio中有一个链接器开关,可以将此限制更改为4gb.

要弄清楚您的进程将消耗多少内存,您必须做一些数学运算.

100000000整数是400兆字节.

添加两个32位指针,现在您可以达到1.2 GB.

但是等等,还有更多...

内存通常以16个字节的块分配,因此每个记录将至少消耗16个字节.该内存中至少有4个字节用于内部管理.但是有了两个指针和一个整数,我们恰好位于16个字节.

所以现在我们达到了1.6 GB.

如果以调试模式运行,则分配中会有更多数据,并且最小记录大小可能会更大.因此,您可能会遇到8、16或更多GB的数据.
32 bits of addressing is 2^32 or 4GB.

In a practical sense, 32 bit applications are commonly limited to 2^31 or 2 GB.
There is a linker switch in Visual Studio to change this limit to 4gb.

To figure out how much memory your process will consume, you''ll have to do some math.

100000000 integers is 400 megabytes.

Add two 32 bit pointers, now you''re up to 1.2 gigabytes.

But wait, there''s more...

Memory is typically allocated in 16 byte blocks so each record will consume at least 16 bytes. At least 4 bytes of that memory is housekeeping. But with two pointers and an integer we''re right at 16 bytes.

So now we''re up to 1.6 gigabytes.

If you''re running in debug mode, a lot more data goes into the allocation and your minimum record size can be much larger. So you might be bumping up against 8, 16, or more gigabytes.


将变量设为无符号长.

像:
无符号长x = 4294967295(最大值)
它只能存储整数.
take the variables as unsigned long.

like:
unsigned long x=4294967295( maximum value)
It can only store integers.


这篇关于进程被操作系统杀死-我所看到的只是控制台上的一条被杀死的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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