In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to locate c++ program abnormal operation in Linux, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.
I encountered some thorny problems, because compiling programs on mips64 often fails to compile, or runs abnormally. It took a long time to locate, and finally solved some problems with colleagues. Below, I share some of the core positioning steps I extracted.
Child threads are not created
Guess: go programs can create child threads, but c++ creation does not come out, but in x86 can be, is not what linux system restrictions?
normal performance
abnormal performance
Solution: add error log for debugging (lowest method)
Find the error point:
Error Log Content
Check the man manual to see if you can find something helpful:
man pthread_attr_setstacksize
Print out the explanation:
ERRORS pthread_attr_setstacksize() can fail with the following error: EINVAL The stack size is less than PTHREAD_STACK_MIN (16384) bytes. On some systems, pthread_attr_setstacksize() can fail with the error EINVAL if stacksize is not a multiple of the system page size.
Translating the above words may produce this error:
EINVAL stack size is less than PTHREAD_STACK_MIN(16384) bytes.
On some systems, pthread_attr_setstacksize() may fail with the error EINVAL if stacksize is not a multiple of the system page size
Query the meaning of the linux error code, and learn that the error code 22 is indeed consistent with what is said in the man manual. There is a problem with the parameter.
error code comparison
The first attempt: expand the thread stack to 16384, but still report error
Error Log Content
According to experience, check the minimum page size, found that it is 16K, and x86 architecture is 4K, the original 20K is not aligned, no wonder the thread can not be created.
View System Page Size
Try in turn, and finally found that 10* 16K child threads were successfully created.
However, it is not accurate. According to its statement, it should be an integer multiple of PAGESIZE. It is suspected that it has a requirement for a minimum value. c++ header file in/usr/include directory, PTHREAD_STACK_MIN is a constant, it is estimated that there will be definitions, try to find
$ grep -rl PTHREAD_STACK_MIN * bits/local_lim.h pthread.h
I found that according to English comments, at least two 64K as thread stack, in order to run a thread.
Tips in system c++ header file
The problem was solved.
Part of thread stuck
I found that although the program is running normally, some functions are not normal. After checking the log, I found that there is a thread that is stuck only halfway through execution.
After looking at the log can locate which thread is stuck, if you can not see from the log also does not matter. Some process stacks can be viewed using the pstack process number.
View process pid:
ps -ef |grep process name
Use gdb to see if there is a problem, two important commands:
gdb attach {pid} #View the stack info thread of the running program #Use it later to view thread information
The wrong location was found, and the fgets() and read() functions appeared, suspecting that the problem was there.
gdb attach command results
Error code location
Suspect 1:_LINE_LENGTH 1024 is too short, the return value of the command exceeds the length of the array itself, overwriting unknown memory.
I have encountered this situation before, and the performance should be that the program directly crashes.
Suspect 2: The execution of the command card, resulting in the latter program is not executed.
According to the parameters printed out by gdb, execute linux command to test, and it is really stuck here!
Using pstree -p {pid} again to check, it is true that the main thread, called the linux command stuck.
View the thread tree for this process
Next, solve the card command problem.
Solution 1: Add timeout to empty return. The following is an example command, not the one I used.
timeout 5 ls -al
It means more than 5 seconds to return.
Solution 2: Find out why this linux command is stuck.
strace ls -al on "how to locate c++ program abnormal operation in Linux" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.