Retrive the information for a address using gdb - gdb

Upon Running strace on a Java Application I notice some long time the syscall(mostly futex).
futex(0x7f8578001fd4, FUTEX_WAIT_PRIVATE, 1311, NULL) = 0 <15.082094>
I really want to understand the wait on futex is for which shared resources over here.
But, I'm not sure how?
I did some googling and found GDB can be helpful for finding the above cause. But unfortunately, I'm not much aware of GDB as I had barely used it before.
Can some help me understand how to find the answer that I'm looking at.

The futex operation is waiting for another thread to release a lock. You should first look at Java-aware tools to see if this is a high-level Java lock. Perhaps even sending SIGQUIT (by pressing Ctrl+\ is sufficient) for that.

Related

How to debug a hanging job resulting from reading from lustre?

I have a job in interruptible sleep state (S), hanging for a few hours.
can't use gdb (gdb will hang when attaching to the PID).
can't use strace, strace will resume the hanging job =(
WCHAN field shows the PID is waiting for ptlrpc. After some search online, it looks like this is a lustre operation. The print files also revealed the program is stuck in reading data from lustre. Any idea or suggestion on how to proceed the diagnose? Or possible reason why the hanging happens?
You can check /proc/$PID/stack on the client to see the whole stack of the process, which would give you some more information about what the process is doing (ptlrpc_set_wait() is just the generic "wait for RPC completion" function).
That said, what is more likely to be useful is to check the kernel console error messages (dmesg and/or /var/log/messages) to see what is going on. Lustre is definitely not shy about logging errors when there is a problem.
Very likely this will show that the client is waiting on a server to complete the RPC, so you'll also have to check the dmesg and/or /var/log/messages To see what the problem is on the server. There are several existing docs that go into detail about how to debug Lustre issues:
https://wiki.lustre.org/Diagnostic_and_Debugging_Tools
https://cug.org/5-publications/proceedings_attendee_lists/CUG11CD/pages/1-program/final_program/Wednesday/12A-Spitz-Paper.pdf
At that point, you are probably best off to check for existing Lustre bugs at https://jira.whamcloud,com/ to search for the first error messages that are reported, or maybe a stack trace. It is very likely (depending on what error is being hit), that there is already a fix available, and upgrading to the latest maintenance release (2.12.7 currently), or applying a patch (if the bug is recently fixed) will sole your problem.

Multithreaded application at boot sequence - C++/Debian

I'm having this obscure problem since 2 days : I created a launch-at-boot application in C++ on a debian system, which worked flawlessly until I integrated some multithreading elements.
There are only 2 threads (1 main and 1 child)
I included -lpthread and -pthread in the makefile
I tried both /.config/autostart and the .desktop file methods (same
result)
The program is lanched with sudo
There is no error/crash anywhere, the main thread works OK, but the
child thread runs 1 iteration only then stops for some reason
even tried to add some sleep in the lxsession boot sequence
If I launch the same command line than in the autostart file in a terminal (sudo or not), it works perfectly.
Its been 2 days and I just have NO CLUE !
If someone experienced this before or can find some logic in it, i'll be ever grateful.
It appears to me that you simply have ... a bug in your new logic. You have made an error in the design of your multi-threading logic, such that the child thread only runs one iteration. (Or, much more likely, stalls in an infinite-wait. Waits for a event that is never signaled, a semaphore that is never raised, a queue that runs dry and is never filled, and so on.)
We can help you further if you post excerpts of the code in question ... only illustrating how the child thread is launched and how it interacts with the parent. (Condition-variables, semaphores, and so-forth, which is probably where the crux of your error lies.)
I would suggest that "all the other stuff is irrelevant." You don't need "a sleep in the boot-sequence" (if the sequence waits for your program to complete, and if it needs to). I suggest that it seems to me that you simply have ... a bug in your new code which introduces multi-threading.
And you might wish to contemplate whether multi-threading is advantageous, given that you had a non-threaded version of the same thing that worked properly. If the processing that is to be done used to be done (successfully) by a single thread, such processing might or might not be more-advantageously processed by "n threads." Should you find-and-fix this bug, or is it just as well to abandon the change and revert back to what worked? Only you can decide that ...
Thank you all for your suggestions.
I found a "fix" : running the startup program in a terminal ('#lxterminal -e url/to/program &' in autostart of lxsession) instead of background seems to fix it SOMEHOW. There is no GUI though ... it is a service.
The multithreaded logic isnt at fault here, not my first shot, and I really want to keep this feature (#Mike Robinson).
I will reconsider the use of sudo as suggested as well, which seems sketchy all things considered. It might get it running in background. thanks # datenwolf.

Termination Signal or Interrupts like Ctrl+C on Linux

I want to run a process that checks my key press state, parallel to my existing infinite loop (from pcap header). I was looking something very similar to GetAsyncKeyState that of Windows.
I tried for a whole week and found its hard to program something similar to GetAsyncKeyState. So, I was using Termination Signal like ctrl+c to perform certain operation.
I wanted to know, if there are some other similar Termination signals that I can catch using program to perform operation of my own?
P.S. I'm a beginner for Linux and C++. Sorry, if my question is stupid.
POSIX makes SIGUSR1 and SIGUSR2 available for application use. Additionally there are the set of realtime signals. A close reading of man (7) signal should provide the basics and ample reference material is available on the web.
That said, it sounds like you are headed toward expanding what is already an awkward hack. Perhaps you should ask a separate question detailing exactly what you are doing and someone can help you with a more appropriate path toward solving your primary problem rather than improvements on a work-around.
you can catch the pid (Process identifier of your program) and with another terminal put
kill -9 {pid}
to get the pid just type in terminal ps -u {username}
or you can open application monitor (it's like the task admin of windows)

Thread Status in Linux

I tried looking for a thread on this subject, however couldn't find one. So posting this question.
Assume, I have created couple of threads in C++ in Linux and the code is running.
Now I would like to monitor the process and the threads of the process using a shell script and do some additional processing.
Also I would need the amount of CPU and Memory being used by each thread. I know that a thread is associated to a process, however my requirement is to identify the resources utilized by this thread.
I couldn't find the exact way to identify the threads associated to a process. I tried using PS however I couldn't find any clues. Running RHEL.
From a man page of ps:
To get info about threads:
ps -eLf
ps axms
The manpage for ps might give you more clues.
In particular, it should tell you that -L shows threads, and -o %cpu,%mem will display the amount of CPU and memory being used.
Note that memory is associated with the process, not with any thread, so there is no concept of "memory used by each thread".
Apart from using Linux commands you can use Generic Memory Manager library. Here it defined ThreadingModel class.

getting a thread state in c++/windows

There must be a function that gets the current status of a thread in the system because
there is this application: http://www.softwareverify.com/cpp/thread-status-monitor/index.html
It must be using some sort of API function or something...
How can I get a thread state myself in C++/Windows?
thanks :)
(this is my last question for today. I promise :))
That's done via Toolhelp library, check information at MSDN : http://msdn.microsoft.com/en-us/library/ms686780%28v=VS.85%29.aspx
You can use the following examples to get the running processes and, when you have a process ID, the threads.
Taking a Snapshot and Viewing Processes
Traversing the Thread List
EDIT: After getting the handle to the thread(s) you are interested in you can call GetExitCodeThread but that will only tell you if the thread is STILL_ACTIVE until it ends, when you can find the exit code.
While searching for the additional information for your comment I also came across this thread on SO which might be of interest to you.
You get the most bang out of WMI, Win32_Thread class. The linked article has a link to the C++ code you need. Experiment with the WMI Code Creator tool.