Find the answer to your Linux question:
Results 1 to 6 of 6
This is my program writing on linux OS.It runs normally on the PC.But when I compile it using the arm-linux-gcc and let it run on processor basing on ARM9 ,it ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2005
    Posts
    2

    C program which can run normally on PC but can not on ARM


    This is my program writing on linux OS.It runs normally on the PC.But when I compile it using the arm-linux-gcc and let it run on processor basing on ARM9 ,it generates error.In my program,setitimer and sigaction are both system call.Thank you very much for your helping.

    Code:
    #include <signal.h>
    #include <sys/time.h>
    #include <time.h>
    void print_msg&#40;int&#41;;
    int main&#40;&#41;
    &#123;
    struct itimerval in_old,in_new;
    struct sigaction act_old,act_new;
    act_new.sa_handler=print_msg; 
    	in_new.it_interval.tv_sec=3;
    	in_new.it_interval.tv_usec=0;
    	in_new.it_value.tv_sec=3;
    	in_new.it_value.tv_usec=0;
    	setitimer&#40;ITIMER_REAL,&in_new,&in_old&#41;;	
    	sigaction&#40;SIGALRM,&act_new,&act_old&#41;;
    
    	printf&#40;"pid=%d\n",getpid&#40;&#41;&#41;;
    while&#40;1&#41;;
    	
    return 0;
    &#125;
    
    void print_msg&#40;int arg&#41;
    &#123;
    	printf&#40;"in signal handler\n"&#41;;
    	printf&#40;"pid=%d\n",getpid&#40;&#41;&#41;;
    &#125;
    when it runs on ARM,"pid=43" shows on the screen at fist.After a while,it gives a error as below:
    Code:
    pid=43
    in signal hanpc &#58; &#91;<4002b5c8>&#93;    lr &#58; &#91;<00000000>&#93;    Not tainted
    sp &#58; 00000000  ip &#58; 00000000  fp &#58; bffffde8
    r10&#58; 40137e60  r9 &#58; 401377ec  r8 &#58; 00000000
    r7 &#58; 00000001  r6 &#58; 000082f4  r5 &#58; 40020f04  r4 &#58; bffffe04
    r3 &#58; 00000000  r2 &#58; 00000007  r1 &#58; 00000000  r0 &#58; 00000000
    Flags&#58; nZcv  IRQs on  FIQs on  Mode USER_32  Segment user
    Control&#58; C000317F  Table&#58; 211E4000  DAC&#58; 00000015
    dler
    now is=3.010000
    pid=43
    Segmentation fault
    Mod edit - added code tags.

  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    That looks very much like a kernel oops. If it really is, then it's probably not anything wrong with your program per se.

    Rather, I think you should look at either the hardware or your kernel configuration. What hardware platform is this, more exactly?

  3. #3
    Linux Enthusiast
    Join Date
    Jan 2005
    Posts
    575
    I don't have experience with these functions but one thing I notice
    is that you don't initialize all the fields of the structure act_new.Try
    doing that.Also you should check that the functions setitimer and
    sigaction return 0.

  4. #4
    Linux Guru
    Join Date
    Oct 2001
    Location
    Täby, Sweden
    Posts
    7,578
    There is some truth to what Santa's little helper says -- you should invoke memset(&act_new, 0, sizeof(act_new)); before beginning to assign to it.

    However, even without that, the kernel still shouldn't oops. Of course, it doesn't look exactly as I'd expect an oops to be, but I can't imagine anything else to output that data. Thus, I'd still take a good look at the hardware and kernel config.

  5. #5
    Just Joined!
    Join Date
    Jul 2005
    Posts
    2

    the solution for the problem

    The error doesn't appear as I modify the program as below:

    Code:
    #include <signal.h>
    #include <sys/time.h>
    #include <time.h>
    void print_msg&#40;int&#41;;
    int main&#40;&#41;
    &#123;
    struct itimerval itimer;
    struct sigaction act_new;
    
    memset&#40;&itimer,0,sizeof&#40;itimer&#41;&#41;;
    memset&#40;&act_new,0,sizeof&#40;act_new&#41;&#41;;
    
    act_new.sa_handler=print_msg; 
    	itimer.it_interval.tv_sec=3;
    	itimer.it_interval.tv_usec=0;
    	itimer.it_value.tv_sec=3;
    	itimer.it_value.tv_usec=0;
    	
    	if&#40;sigaction&#40;SIGALRM,&act_new,0&#41;&#41;
    		printf&#40;"at sigaction\n"&#41;;
    
    	if&#40;setitimer&#40;ITIMER_REAL,&itimer,0&#41;&#41;
    		printf&#40;"at setitimer\n"&#41;;	
    	
    	printf&#40;"pid=%d\n",getpid&#40;&#41;&#41;;
    while&#40;1&#41;;
    	
    return 0;
    &#125;
    
    void print_msg&#40;int arg&#41;
    &#123;
    	printf&#40;"in signal handler\n"&#41;;
    	printf&#40;"pid=%d\n",getpid&#40;&#41;&#41;;
    &#125;
    Mod edit - Added code tags.

  6. #6
    Linux Enthusiast
    Join Date
    Jan 2005
    Posts
    575
    Great.The only remark is that
    Code:
    memset&#40;&itimer,0,sizeof&#40;itimer&#41;&#41;;
    is not really needed because you initialize all the fields of the structure
    further down in your programme.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •