1

I was running some C code that drove a stepper motor. The general flow was that it would take user input for the number of steps, maximum speed, and acceleration (scanf commands). Then it would go through a set of whiles and ifs that would generate the profile. It would then activate the stepper motor, wait 0.5s, run the profile, wait another 0.5s, and repeat the whole process from the beginning. It was an infinite while-loop, and the way I would end the program was with Ctrl-C.

One day, I absentmindedly closed out of the command line without Ctrl-Cing out of my code. To my great surprise, it instantly began to run the last profile I had set. It then kept on running that profile, over and over, until I rebooted my Pi.

Why did this happen?

I am using the default Raspbian distro (current as of December 2015, I think) on a Pi 2B with WiringPi.

EDIT:Turned out I didn't have error handling for Ctrl-C. Also, my scanf read into variables, which were reset by the scanf's. If the scanf's were skipped, then I would get the observed symptoms of just running the profile over and over again.

  • what do you mean by "closed out of the command line"? – JayEye May 1 '16 at 23:48
  • @JayEye I mean that I hit the little red X in the upper right corner. – dpdt May 1 '16 at 23:49
  • Were you running tmux or screen? – Jacobm001 May 2 '16 at 2:33
  • Does the application spawn a seperate process? – Jacobm001 May 2 '16 at 2:34
  • No, it's one big infinite while-loop. No error handling. – dpdt May 2 '16 at 12:56
1

closing your terminal window obviously did not kill your program. However, because the terminal from which your program was getting its standard input stopped existing (technically: the pty side was closed when the terminal emulator window closed), every read() system call of your program returned an end-of-file condition, which your program interpreted incorrectly, thought it read something, and acted accordingly.

None of this is pi-specific, of course.

0

Killing the terminal does not kill all the processes you launched since you opened it. What you can do (other than rebooting the Pi), is use a task manager (I believe top comes with Raspbian, I personally prefer htop) and use it to find and kill your process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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