2

I've got a C++ application which connects over a USB serial link to a microprocessor, (similar to an Arduino). I use termios.h as my serial wrapper.

I'm debugging using cgdb on Mac OS X 10.7.3.

When I:

  • cgdb build/my-process
  • Set some breakpoints, etc, do some debugging
  • Find a bug, or try to exit the still running process using kill inside cgdb

the process hangs. cgdb refuses to ever kill the process - just sits there. I'm fairly sure this is because if I kill from halfway through the application, I never release the /dev/ttyUSB device that I'm accessing the microcontroller through. I'm not sure if something gets locked and never unlocked, but cgdb never exits.

I've tried:

  • Basic interrupts: Ctrl+C
  • ps aux | grep 'my-process',kill -9 [pid]`.
  • ps aux | grep cgdb, kill -9 [pid].
  • sudo versions of the above.

Nothing kills either cgdb or the process running in it.

If I remove the USB cable (terminate connection to microprocessor), (I thought that might crash the crashed process), I start seeing ~50% available CPU being used (not sure on what), and everything locks up. I don't manage to crash the application.

How do you: (a) exit cleanly without locking everything up from cgdb or gdb while in the middle of debugging a process, or (b) kill / cleanly (although 'cleanly' would just be icing on the cake) stop a process that's stopped while you're debugging it that isn't responding to kill -9 without rebooting?

simont
  • 68,704
  • 18
  • 117
  • 136

2 Answers2

5

You can't kill a process that's in an I/O wait. That's been true for most if not all Unix kernels from the dawn of the epoch.

It sounds like a debugger (or any process that's ptraceing another) that's stuck in an I/O wait can't be killed, either.

smparkes
  • 13,807
  • 4
  • 36
  • 61
  • Nope, it's essentially an uninterruptible state. The only way to get out the state is to cause the kernel I/O operation to complete, successfully or not. – smparkes Feb 25 '12 at 21:07
  • That's a slight pain - thanks. I've been bashing my head trying to figure out how to kill the silly thing for a few days now. – simont Feb 25 '12 at 21:16
0

ptrace or pgrep

I would try "pgrep -l cgdb" very handy for listing the pid...

Chyper64
  • 113
  • 4