Thread: strace can SIGSEGV lead to SIGKILL?

  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    42

    strace can SIGSEGV lead to SIGKILL?

    Hi There,

    I'm still afflicted by SIGKILLs in my application and I have not been able to locate the error with gdb and instead I put on strace now. And following output is what i got just before the SIGKILL:
    Code:
    [pid  1241] --- SIGSEGV (Segmentation fault) @ 0 (0) ---
    Process 1241 detached
    [pid  1245] <... nanosleep resumed> NULL) = ? ERESTART_RESTARTBLOCK (To be restarted)
    [pid  1221] <... nanosleep resumed> {4, 868304250}) = ? ERESTART_RESTARTBLOCK (To be restarted)
    [pid  1246] <... read resumed> 0xbebff918, 1024) = ? ERESTARTSYS (To be restarted)
    [pid  1242] <... accept resumed> 0xbf3ffb88, [16]) = ? ERESTARTSYS (To be restarted)
    [pid  1259] <... recv resumed> 0xbe9ffcff, 1, 0) = ? ERESTARTSYS (To be restarted)
    [pid  1243] <... mq_timedreceive resumed> "\330\21\6\10", 4, -1088422596, NULL) = ? ERESTARTSYS (To be restarted)
    [pid  1244] <... mq_timedreceive resumed> "\0\1\17\0y\0\0\0T0001\0\0\0", 16, 0, NULL) = ? ERESTARTSYS (To be restarted)
    [pid  1240] <... poll resumed> )        = -1 EINTR (Interrupted system call)
    [pid  1245] +++ killed by SIGKILL +++
    [pid  1221] +++ killed by SIGKILL +++
    [pid  1246] +++ killed by SIGKILL +++
    [pid  1242] +++ killed by SIGKILL +++
    [pid  1259] +++ killed by SIGKILL +++
    [pid  1243] +++ killed by SIGKILL +++
    [pid  1244] +++ killed by SIGKILL +++
    +++ killed by SIGKILL +++
    Kinda looks as if the SIGSEV up there eventually lead to the SIGKILL - is this possible at all? I've caught a couple of segfault in my code with gdb but sometimes (most of the times) it would say SIGKILL only on termination. I have an idea where the segfault may come from... please take this thread into consideration:'another SEGFAULT'

    Hints and suggestions are appreciated...
    Thanks!
    Ron

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by cerr
    please take this thread into consideration:'another SEGFAULT'
    and there lies your answer. As Salem said, find you seg fault and fix it. He has listed pointers in that thread.

  3. #3
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Haven't used strace much. It was my understanding that a SIGSEGV is death, which this test demonstrates:
    Code:
    int main(void) {
    	char *x;
    	strcpy(x,"hello world");
    	return 0;
    }
    The strace on this ends:
    +++ killed by SIGSEGV +++

    However, maybe there are circumstances where the OS responds to SIGSEGV by explicitly SIGKILLing the process's children, which is probably what is happening here. 1241 was killed by SIGSEGV -- the sigkills are to other processes. Makes sense if you are using pthreads I guess.*

    In any case, as Kennedy points out, your problem is the seg fault, plain and simple. You need to solve that -- regardless of the mechanism, a segmentation fault must cause the violating process to die because it cannot be allowed to access memory outside of itself.

    * Based on that, you may want to consider which thread of functionality 1241 represents, that's where the fault is...
    Last edited by MK27; 01-14-2010 at 09:41 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  4. #4
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Is there some reason you haven't run this through Valgrind yet?
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  5. #5
    Registered User
    Join Date
    Dec 2009
    Posts
    42
    Quote Originally Posted by jeffcobb View Post
    Is there some reason you haven't run this through Valgrind yet?
    Nah, haven't gotten the code compiled to run on our target platform yet...

  6. #6
    Registered User
    Join Date
    Dec 2009
    Posts
    42

    Unhappy

    Quote Originally Posted by MK27 View Post
    [snip]

    However, maybe there are circumstances where the OS responds to SIGSEGV by explicitly SIGKILLing the process's children, which is probably what is happening here. 1241 was killed by SIGSEGV -- the sigkills are to other processes. Makes sense if you are using pthreads I guess.*

    In any case, as Kennedy points out, your problem is the seg fault, plain and simple. You need to solve that -- regardless of the mechanism, a segmentation fault must cause the violating process to die because it cannot be allowed to access memory outside of itself.

    [snip]
    Okay, I found one of the SIGSEGVs I believe. It's because pointers were freed but not set to NULL which would cause stale pointers... that'been corrected.
    However, I still seem to be getting a segfault every now and then (a lot less often)... I caught them with strace,
    once I got this one:
    Code:
    [pid 15389] sched_setscheduler(15389, SCHED_OTHER, { 0 }) = 0                                                                                                                                           
    [pid 15389] --- SIGSEGV (Segmentation fault) @ 0 (0) ---
    and another time it looked like this:
    Code:
    [pid 19908] getdents(20, /* 13 entries */, 3933) = 308
    [pid 19908] --- SIGSEGV (Segmentation fault) @ 0 (0) ---
    Can I say that the most recent line before the segfault is what is making the seg fault happening?
    If so, in the 2nd occurence, getdents is referring to my getdir() function which looks like this:
    Code:
    int getdir(char *path, char ***filelist)
    {
      int items=0;
      char **temp=NULL;
      char filename[1024]={0};
      struct dirent *dp;
      DIR *dir = opendir(path);
      if (dir==NULL){
        syslog(LOG_NOTICE, "nlog: Error opening log_record directory %s, Errno: %s", path, strerror( errno ));
        printf("Error opening log_record directory %s, Errno: %s", path, strerror( errno ));
        return -1;
      }
      while((dp=readdir(dir))!=NULL){
        if(strstr(dp->d_name, "log_record")!=NULL){
          //sprintf(filename,"%s%s",path,dp->d_name);      
          snprintf(filename,sizeof(filename),"%s%s",path,dp->d_name);
          temp = realloc((*filelist), (items+1) * sizeof(*temp));
          if (temp == NULL) {
            while (--items >= 0)
              free ((*filelist)[items]);
            free ((*filelist));
            syslog(LOG_NOTICE, "nlog: Error reallocating memory in filelist\n");
    	printf("Error reallocating memory for filelist\n");
    	closedir(dir);
            return -1;
          }
          (*filelist) = temp;
          (*filelist)[items] = malloc(strlen(filename)+1);
          if ((*filelist)[items] == NULL) {
            syslog(LOG_NOTICE, "nlog: Error allocating memory for filename\n");
            return -1;
          }
          strcpy ((*filelist)[items], filename);
          ++items;
        }    
      }
      closedir(dir);
      return items;
    }
    Any one a clue what may be wrong here?
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compute target lead
    By VirtualAce in forum Game Programming
    Replies: 18
    Last Post: 10-02-2009, 09:41 AM
  2. Get faulting address on SIGSEGV
    By kruemelmonster in forum Linux Programming
    Replies: 12
    Last Post: 04-21-2009, 10:29 PM
  3. Causing and trapping SIGSEGV
    By ampersand11 in forum C Programming
    Replies: 2
    Last Post: 01-22-2008, 05:26 PM
  4. WANTED: Lead Programmer
    By fluid_hres in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 05-10-2006, 07:25 PM
  5. debugging: sigsegv, segmentation fault???
    By Gonzo in forum C Programming
    Replies: 9
    Last Post: 09-16-2003, 06:56 AM