I was running a program in C from the terminal in Linux and I get the message "Finished (killed)". From the output obtained I see that the execution is more or less always killed at the same point. I am also working with a huge amount of data and I am executing the program locally in my computer.
我在Linux的终端上运行了一个C程序,我得到了消息“Finished(killed)”。从获得的输出中我看到执行或多或少总是在同一点被杀死。我也在处理大量数据,我正在计算机本地执行程序。
Writing in the console ulimit -a I get the following information:
在控制台中写入ulimit -a我得到以下信息:
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 29117
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 29117
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
But I see in there normal values.
但我在那里看到了正常的价值观。
I do not know what to do in order to get the whole execution completed. I've optimized the code and freed memory but I get the same problem "(killed)".
我不知道该怎么做才能完成整个执行。我已经优化了代码并释放了内存但我遇到了同样的问题“(已杀死)”。
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define T 100
#define dt 1.e-4
#define itmax (T/dt)
#define a 0.27
#define K1 0.15
#define K2 1.e2
#define pp 1.e3
#define s 2
#define TWOPI (6.2831853071795864769252867665590057683943387987502)
#define IM1 2147483563
#define IM2 2147483399
#define AM (1.0/IM1)
#define IMM1 (IM1-1)
#define IA1 40014
#define IA2 40692
#define IQ1 53668
#define IQ2 52774
#define IR1 12211
#define IR2 3791
#define NTAB 32
#define NDIV (1+IMM1/NTAB)
#define EPS 1.2e-7
#define RNMX (1.0-EPS)
double ran2(double *idum){
int j;
long k;
static long idum2=123456789;
static long iy=0;
static long iv[NTAB];
float temp;
if (*idum <= 0) {
if (-(*idum) < 1) *idum=1;
else *idum = -(*idum);
idum2=(*idum);
for (j=NTAB+7;j>=0;j--) {
k=(*idum)/IQ1;
*idum=IA1*(*idum-k*IQ1)-k*IR1;
if (*idum < 0) *idum += IM1;
if (j < NTAB) iv[j] = *idum;
}
iy=iv[0];
}
k=(*idum)/IQ1;
*idum=IA1*(*idum-k*IQ1)-k*IR1;
if (*idum < 0) *idum += IM1;
k=idum2/IQ2;
idum2=IA2*(idum2-k*IQ2)-k*IR2;
if (idum2 < 0) idum2 += IM2;
j=iy/NDIV;
iy=iv[j]-idum2;
iv[j] = *idum;
if (iy < 1) iy += IMM1;
if ((temp=AM*iy) > RNMX) return RNMX;
else return temp;
}
double RANDN(double seed){
return sqrt(-2.0*log(ran2(&seed)))*cos(TWOPI*ran2(&seed));
}
double rnd(){
return (double) rand() / (double) RAND_MAX;
}
int main(){
int j, rows, d;
d=0;
double *t;
t=(double *) malloc((itmax)*sizeof(double));
double **x, **y;
x=(double **)malloc(2*sizeof(double*));
y=(double **)malloc(2*sizeof(double*));
for(rows=0; rows<2; rows++){
x[rows]=(double*)malloc(itmax*sizeof(double));
y[rows]=(double*)malloc(itmax*sizeof(double));
}
double p, L, C, bC, Qx, Qy;
double bx, by Qbx, Qby, KK, KKK, dt2;
srand(time(NULL));
t[0]=0;
for(rows=0; rows<2; rows++){
x[rows][0]=10+rows*i;
y[rows][0]=1300;
}
L=s*0.0001;
KK=K1*K1;
KKK=K2*K2;
dt2=0.5*dt;
C=KK*KKK;
bC=a*C;
for(j=0; j<=itmax; j++){
p=pp-x[0][j]+x[1][j];
Qx=a+bC/(KK+C)-a*x[0][j]*y[0][j];
Qy=y[1][j]-y[0][j];
bx=x[0][j]+dt*Qx+L*RANDN(rnd()+2);
by=y[0][j]+dt*Qy+L*RANDN(rnd()+2);
Qbx=a+bC/(KK+C)-a*bx*by-a*bx;
Qby=y[0][j]-y[1][j];;
x[0][j+1]=(bx+x[0][j])/2+(Qbx+Qx)*2;
y[0][j+1]=(by+y[0][j])/2+(Qby+Qy)*2;
Qx=a+bC/KK-a*x[1][j]*y[1][j];
Qy=y[1][j];
bx=x[1][j]+dt*Qx;
by=y[1][j]+dt*Qy;
Qbx=a+C/(KK+C)-a*bx*by-a*bx;
Qby=by*(y[1][j]-y[0][j]);
x[1][j+1]=(bx+x[1][j])/2+(Qbx+Qx)*dt2+L*RANDN(rnd()+2);
y[1][j+1]=(by+y[1][j])/2+(Qby+Qy)*dt2+L*RANDN(rnd()+2);
if(j==d){
d+=T;
printf("%G %G %G %G %G\n",t[j],x[0][j],x[1][j],y[0][j],y[1][j]);
}
}
return 0;
}
2 个解决方案
#1
3
You almost certainly lack a swap partition, or you have some other utility monitoring the amount of available free memory, and therefore your program is killed because it consumes too much memory, up to the point that there is no free ram left.
你几乎肯定没有交换分区,或者你有一些其他的实用程序监视可用的可用内存量,因此你的程序被杀死,因为它消耗了太多的内存,直到没有剩余的免费ram。
You can use htop or conky to have a clear view of the issue.
您可以使用htop或conky清楚地查看问题。
If instead you had a swap partition then your system would attempt to swap the memory from/to the disk, and this would most likely freeze it. This is a much worse scenario, because in most cases the only action that you can take to get the system back working is to reboot it: in my experience, when the system freezes then it no longer responds to any keyboard input.
如果你有一个交换分区,那么你的系统会尝试从磁盘交换内存,这很可能会冻结它。这是一个更糟糕的情况,因为在大多数情况下,您可以采取的唯一操作是让系统重新启动它:根据我的经验,当系统冻结时它不再响应任何键盘输入。
On my system it takes 2m26s for your executable to fill over 50% of the available 8GB of RAM, not counting the additional 32% that is occupied by the other running programs.
在我的系统上,你的可执行文件需要2分26秒来填充超过50%的可用8GB内存,不包括其他正在运行的程序占用的额外32%。
You might want to use a memory leak profiling tool (e.g. valgrind) to check for potential leaks, or simply inspect the source code manually. If you can't reduce its memory footprint, then your only option is to look for a much more powerful machine with a larger pool of RAM.
您可能希望使用内存泄漏分析工具(例如valgrind)来检查潜在的泄漏,或者只是手动检查源代码。如果你不能减少它的内存占用,那么你唯一的选择是寻找一个功能更强大的机器,它有更大的RAM池。
#2
2
Compile and link with debugging information using -g
, then run the program under control of a debugger such as gdb
and watch where it stops. You should see which line of source code causes the problem that gets your program killed by the system.
使用-g编译并链接调试信息,然后在调试器(如gdb)的控制下运行程序,并观察它停止的位置。您应该看到哪行源代码导致系统杀死程序的问题。
$ gcc -O2 -g -o my_program my_program.c
$ gdb my_program
gdb> run
If your program needs command line arguments, type them on the run
command
如果您的程序需要命令行参数,请在运行命令中键入它们
gdb> run arg1 arg2
#1
3
You almost certainly lack a swap partition, or you have some other utility monitoring the amount of available free memory, and therefore your program is killed because it consumes too much memory, up to the point that there is no free ram left.
你几乎肯定没有交换分区,或者你有一些其他的实用程序监视可用的可用内存量,因此你的程序被杀死,因为它消耗了太多的内存,直到没有剩余的免费ram。
You can use htop or conky to have a clear view of the issue.
您可以使用htop或conky清楚地查看问题。
If instead you had a swap partition then your system would attempt to swap the memory from/to the disk, and this would most likely freeze it. This is a much worse scenario, because in most cases the only action that you can take to get the system back working is to reboot it: in my experience, when the system freezes then it no longer responds to any keyboard input.
如果你有一个交换分区,那么你的系统会尝试从磁盘交换内存,这很可能会冻结它。这是一个更糟糕的情况,因为在大多数情况下,您可以采取的唯一操作是让系统重新启动它:根据我的经验,当系统冻结时它不再响应任何键盘输入。
On my system it takes 2m26s for your executable to fill over 50% of the available 8GB of RAM, not counting the additional 32% that is occupied by the other running programs.
在我的系统上,你的可执行文件需要2分26秒来填充超过50%的可用8GB内存,不包括其他正在运行的程序占用的额外32%。
You might want to use a memory leak profiling tool (e.g. valgrind) to check for potential leaks, or simply inspect the source code manually. If you can't reduce its memory footprint, then your only option is to look for a much more powerful machine with a larger pool of RAM.
您可能希望使用内存泄漏分析工具(例如valgrind)来检查潜在的泄漏,或者只是手动检查源代码。如果你不能减少它的内存占用,那么你唯一的选择是寻找一个功能更强大的机器,它有更大的RAM池。
#2
2
Compile and link with debugging information using -g
, then run the program under control of a debugger such as gdb
and watch where it stops. You should see which line of source code causes the problem that gets your program killed by the system.
使用-g编译并链接调试信息,然后在调试器(如gdb)的控制下运行程序,并观察它停止的位置。您应该看到哪行源代码导致系统杀死程序的问题。
$ gcc -O2 -g -o my_program my_program.c
$ gdb my_program
gdb> run
If your program needs command line arguments, type them on the run
command
如果您的程序需要命令行参数,请在运行命令中键入它们
gdb> run arg1 arg2