如何使用NetBeans调试器连接CentOS 7上运行的C进程?
Hey there, let's get you set up to debug a running C process with NetBeans on CentOS 7, since you've already got the Java process debugging sorted out. Here's a step-by-step breakdown that should work for your environment:
1. Prep Your Tools First
First off, make sure NetBeans has the C/C++ development plugin installed—this isn't included by default. Head to Tools > Plugins, search for "C/C++ Development Pack", and install it if you haven't already.
On CentOS 7, you'll also need the GNU Debugger (gdb) and basic dev libraries. Install them via yum:
sudo yum install gdb gcc-c++ glibc-devel
2. Find Your Running C Process's PID
You'll need the Process ID (PID) of the C program you want to debug. Grab it with one of these commands:
# Search for the process by name ps aux | grep <your-c-process-name> # Or get the PID directly if you know the exact executable name pidof <your-c-process-name>
Jot down that PID—you'll need it in the next step.
3. Attach NetBeans to the Process
- Open NetBeans and either load your existing C/C++ project (having the source code will make debugging way smoother) or create a blank C/C++ project (this works even if you don't have the full project set up, but source code helps with breakpoints).
- Go to the
Debugmenu at the top and selectAttach to Process. - In the pop-up window:
- Choose
Localfrom the connection type dropdown (since you're working on the same CentOS machine). - Use the filter bar to search for your process by name or paste the PID you noted earlier.
- Select the correct process and click
Attach.
- Choose
4. Start Debugging!
Once attached, you can use all of NetBeans' standard debugging tools: set breakpoints in your source code, inspect variable values, step through line-by-line execution, and more.
Quick Tips to Avoid Headaches
- If your C process is running as root, you'll need to launch NetBeans with sudo privileges to attach without permission errors:
sudo netbeans - Double-check that the source code in NetBeans matches the binary you're debugging—if they don't match, breakpoints might not hit where you expect them to.
- If you run into "permission denied" issues, make sure gdb is installed correctly and you have the right access to the process.
内容的提问来源于stack exchange,提问作者Tim Edwards

