I am new to raspberry pi (Raspbian). Any guidance in the matter will be appreciated!

I have written a C code which includes C Filehandling & wiringPi.h library for GPIO manipulations.

I have narrowed down the problem to the empty infinite loop. If I include it in the main function, my terminal freezes and not even Hello world! gets printed.

Should I do implement this infinite loop in some other way because it's a raspberry? If so, then how?

This is how the main() function looks:

// Main function
int main (void)
  printf("Hello world!");

  // Read updated preferences file

  // Initialize WiringPi Library
  wiringPiSetup () ;

  // Setup falling edge interrupt on INPUT pin
  wiringPiISR (INPUT, INT_EDGE_FALLING, &myInterrupt0) ;

  // Setup OUT1 & OUT2 as output
  pinMode (OUT1, OUTPUT) ;
  pinMode (OUT2, OUTPUT) ;

  // Initialize motor

  for (;;)
    // Empty loop since all the work is done in Interrupt routine


  return 0 ;

Here is the interrupt routine:

// Interrupt Service routine
void myInterrupt0 (void) { 




  • \$\begingroup\$ If you accept an answer you may also want to upvote it. It would be strange if an answer is good enough to actually solve your problem, but not "useful" as the upvote reason states. \$\endgroup\$
    – pipe
    Commented Sep 10, 2017 at 7:36
  • 1
    \$\begingroup\$ One comment about your code: the empty loop will cause 100% CPU load. Place a delay inside to avoid this. And a while(1){} is more readable than a for(;;) {} \$\endgroup\$
    – sweber
    Commented Sep 10, 2017 at 7:40
  • \$\begingroup\$ @sweber If there is some desktop OS like Linux, it will be pre-emptive. Not quite sure what you wish to achieve with the delay() then, spook up the context switching? \$\endgroup\$
    – Lundin
    Commented Sep 11, 2017 at 14:43
  • \$\begingroup\$ @Ludin: To be honest, I have trouble understanding your comment. An infinite, emtpy loop causes CPU load. It would be best to let the main function sleep forever, but looping over long delays works quite well, too. An empty loop is often used on simple microcontrollers, but this is a pi, a small computer... \$\endgroup\$
    – sweber
    Commented Sep 11, 2017 at 17:46
  • \$\begingroup\$ @sweber You let the process go down by waiting for some manner or wake-up event. Adding delays is a poor solution, your program will basically just sit there screaming "ok context switch now, zzz, ok context switch now, zzz..." over and over. A preemptive OS will be able to do that by itself, without your process manually yielding its time slice over and over. \$\endgroup\$
    – Lundin
    Commented Sep 12, 2017 at 6:43

1 Answer 1


Streams, to which functions like printf() write, by default exhibit line buffered behavior, and do not typically actually write the buffered output until either a line ending is encountered or an explicit fflush() is called.

Therefore, either change your message to include a newline:

printf("Hello world!\n");

Or explicitly flush the stream

printf("Hello world!");

As this is really a generic programming question having nothing in particular to do with hardware or the Raspberry Pi, it would probably have better belonged on Stackoverflow - where it has no doubt been answered numerous times in the past. Though it's quite understandable why the use of interrupts in an adjacent part of the code could be distracting, even though actually not relevant to the issue.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.