In the Linux system operation, often encounter multi-process debugging problems, in fact, multi-process debugging is not as complicated as imagined, the following small series will introduce you how to debug Linux Process procedures, interested friends may wish to understand.
debugging
multi-process:
(1) follow-fork-mode
set follow-fork-mode [parent |
Child] ———— After fork, choose to debug the parent process or child process
(parent: continue to debug the parent process after fork; child: fork after debugging the parent process. The default is to debug the parent after fork Process)
set detach-on-fork [on |
Off] ———— Indicates whether gdb disconnects debugging of a process after fork, or is controlled by gdb
(on: disconnects the process specified by follow-fork-mode; Off: gdb will control the parent process and child process, the process specified by follow-fork-mode will be debugged, and the other process will be placed in a pause state)
(2)attach pid
gdb under ubuntu To use the attach pid permission is not enough, you need to switch to root, or you can add permissions to gdb with sudo chmod +s /usr/bin/gdb.
Using attach requires adding a sleep() statement at the beginning of the parent-child process code to let the process sleep, then running the process in the background, getting the child process pid through ps, and finally attach pid into the debug child process.
eg:
$./test & //Make the process test run in the background
$ps -ef |
Grep test //View process pid
The result looks like this:
XXX 12345 23456 ——————————&mdash ;————— . /test //parent process
XXX 12346 12345 ———————————————— /test //child process, the first number here is the child process pid
$ gdb -q test
(gdb)attach 12346 //attach to the child process
Added sleep() can be a statement like this:
while(pause) //pause is a flag variable
sleep(1);
Debugging in gdb You only need to set pause=0 to make the condition unsatisfiable and execute the subsequent code.
(3) gdb wrapper
When the parent process forks the child process, the child process will immediately call the exec function to execute the new code. In this case, you can also use gdb wrapper. The advantage is that you don't have to add extra code.
Put a process in the background under Linux:
(1). /test &
(2)“. /test” Then press “ctrl+z” to put the process back into the background with the number returned by “bg %num”
Pull the process back to the foreground under Linux:
Use “fg%num”
The above is the Linux multi-process program debugging method introduced, multi-process debugging we usually use gdb, when you use the gdb debugging tool.
The TCP port range of the Linux system can be modified. Appropriately adjust the TC
In the Linux system, you need to find some problems after assigning variables, you need to delete or
mono is a cross-platform ·NET runtime environment developed by Novell. It ca
In many cases, Linux is used as a server to allow computers on the Internet to acce
How Linux uses the kill command to force a process to terminate
How to use the "yes" command in Linux?
Solution for Docker container and host time out of sync
What should I do if the GRUB boot error occurs when CentOS is booting?
How to install Twisted on Ubuntu?
Linux installation using fail2ban method
How to identify Linux soft links and hard links
Gulp error under Linux Error: What should I do with ENOSPC?
How to install Ruby and rvm on Ubuntu 11.04
Linux prompts [root@localhost ~]# iptraf when executing commands?
Does Linux use the ODBC method or the DBI way to install the R language extension package?
What is the use of IE to clean up the address bar?
Microsoft Win10 free upgrade notification to open self-destruction countdown mode
How to enable the hidden function in Windows 8?
What caused the small icon of the window to become garbled
Win7 how to cancel the network authentication prompt box
Threat user password, WP8.1 version of IE has serious security vulnerabilities
How to modify the number of magnetic posts in the Win8 system start screen