linux - Program in C executed and the terminal shows: Finished (killed) -


i running program in c terminal in linux , message "finished (killed)". output obtained see execution more or less killed @ same point. working huge amount of data , executing program locally in computer.

writing in console ulimit -a following information:

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 see in there normal values.

i not know in order whole execution completed. i've optimized code , freed memory 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 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 (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);     (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, 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; } 

you lack swap partition, or have other utility monitoring amount of available free memory, , therefore program killed because consumes memory, point there no free ram left.

you can use htop or conky have clear view of issue.


if instead had swap partition system attempt swap memory from/to disk, , freeze it. worse scenario, because in cases action can take system working reboot it: in experience, when system freezes no longer responds keyboard input.


on system takes 2m26s executable fill on 50% of available 8gb of ram, not counting additional 32% occupied other running programs.


you might want use memory leak profiling tool (e.g. valgrind) check potential leaks, or inspect source code manually. if can't reduce memory footprint, option more powerful machine larger pool of ram.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -