What do you do with badly behaving 3rd party processes in Linux? - linux

Anytime I have a badly behaving process (pegging CPU, or frozen, or otherwise acting strangely) I generally kill it, restart it and hope it doesn't happen again.
If I wanted to explore/understand the problem (i.e. debug someone else's broken program as it's running) what are my options?
I know (generally) of things like strace, lsof, dmesg, etc. But I'm not really sure of the best way start poking around productively.
Does anyone have a systematic approach for getting to the bottom of these issues? Or general suggestions? Or is killing & restarting really the best one can do?
Thanks.

If you have debugging symbols of the program in question installed, you can attach to it with gdb and look what is wrong there. Start gdb, type attach pid where pid is the process id of the program in question (you can find it via top or ps). Then type Ctrl-C to stop it. Saying backtrace gives you the call stack, that means it tells which line of code is currently running and which functions called the currently running function.

Related

Does anyone have an idea how to find what or who is calling findstr.exe to run speratically?

I have Windows 10, and about a week ago I installed Avast Device Driver Updater and it did update my chipset, intel processor, and Intel RAID drivers, which were the only ones I allowed it to with no problems. However a couple of days after I started noticing that a CMD window just pops up out of no where and seemingly when it wants to, and it runs a bunch of FINDSDR commands on a bunch of directories that I don't have on my laptop. The window then closes before I have a chance to read any of the paths and quicker then I can catch it to copy anything. The problem is that I can not find the program, shell script, or anything that would be running that might be causing this to run.
I do know that it always tries the to find the same directories, and they fail every time. But I just cant read them... I checked and according to Avast, the Driver Updater does not run any scripts like this, so it should not be the updater process, and just to be sure, I have stopped it from Auto Loading at Boot, and I turned off all it's functions in the settings.
So, I would like to know if anyone knows of any tricks that would help me identify what is calling the findstr.exe, or a way to trap it, while it's running (though even it I trapped it, I don't know how I can use that info to find the culprit that is causing it to run. I am hoping some one know how I can figure out what or where its running from and whos making it run. Any ideas? Thanks a bunch in advance!

How can I find a reason that a program stalls?

I'm handling a program which controls a car.
The program has a pretty large scale and it was made by other people.
So I don't understand completely how it works.
But I have to apply it and make a car moving.
The problem I'm facing is that the program often stalls with no error, no segmentation.
If it crashes, I can trace the cause with gdb or something like that.
But it does not crash, it silently stops.
How can I find the cause?
From your description - program silently stops - I understand that your program simply and gracefully exited, but not from your expected flow. This can happen for many reasons - for example, maybe your program enters illegal flow and some sub-component, such as standard library or other library decide that program should exit, and thus calls c-runtime exit() or directly calls Kernel32!ExitProcess().The best way to debug this flow is to attach a debugger and set a breakpoint on these two methods and find out who is calling them.If you mean your program enters a deadlock and halts then also you will need to attach a debugger and find out who is stuck.

Kernel died, restarting in the middle of my simulation (spyder)

I am using the spyder interface with a python script that works through many time steps in succession. At a random point in my code, the process will terminate and the console will say "kernel died, restarting...". I tried running the same script in pycharm and the process also terminates, seemingly at a random point, with some exit code which I assume means the same thing.
Anyone have any tips on how to get rid of this problem? Even a workaround so I can get some work done. This is incredibly frustrating.
Note: I recently moved and got a new router and internet service, not sure if that might affect things.

view output of already running processes in linux

I have a process that is running in the background (sh script) and I wonder if it is possible to view the output of this process without having to interrupt it.
The process ran by some application otherwise I would have attached it to a screen for later viewing. It might take an hour to finish and i want to make sure it's running normally with no errors.
There is already an program that uses ptrace(2) in linux to do this, retty:
http://pasky.or.cz/dev/retty/
It works if your running program is already attached to a tty, I do not know if it will work if you run your program in background.
At least it may give some good hints. :)
You can probably retreive the exit code from the program using ptrace(2), otherwise just attach to the process using gdb -p <pid>, and it will be printed when the program dies.
You can also manipulate file descriptors using gdb:
(gdb) p close(1)
$1 = 0
(gdb) p creat("/tmp/stdout", 0600)
$2 = 1
http://etbe.coker.com.au/2008/02/27/redirecting-output-from-a-running-process/
You could try to hook into the /proc/[pid]/fd/[012] triple, but likely that won't work.
Next idea that pops to my mind is strace -p [pid], but you'll get "prittified" output. The possible solution is to strace yourself by writing a tiny program using ptrace(2) to hook into write(2) and writing the data somewhere. It will work but is not done in just a few seconds, especially if you're not used to C programming.
Unfortunately I can't think of a program that does precisely what you want, which is why I give you a hint of how to write it yourself. Good luck!

Scp as background job?

Here is the problem:
i must move some files from one host to another, ok i use scp for
it.
But i need use it without blocking console, so should use scp &. But my job will killed after disconnecting (a heard it`s something called hup signal) so i found some tricks for fixing this.
But i wanna see progress bar after some time and all that tricks couldnt work because when i use jobs - it display jobs that only for these session.
So how to fix my problem ?
P.S. Sorry for my English.
I am not sure it is what you want but I'll suggest GNU Screen. It allows you to run a program so that when you log out, the program continues execution in the background. Later you can log back in and resume interaction with the program.
I guess you want ability to detach -and- attach terminal - The tool is called screen.

Resources