paolojo
Posts: 117
Joined: Mon Oct 26, 2015 3:32 pm

How to monitor threads activities

Tue Oct 11, 2016 10:28 am

Hi!
Could you suggest me a method to analize what are the threads that are runnig (something like "task manager" in windows)?
My python script launches simultaneously three thread every about five seconds. Each thread runs for about one second then he finishes his activities.
The problem is that after the script launches about 90 times the above theads, the raspy crashes.
My doubt is: probably the threads don't finish but remain in background causing CPU crash.
Could you help me?
Thanks a lot

User avatar
topguy
Posts: 6782
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: How to monitor threads activities

Tue Oct 11, 2016 11:03 am

Are you saying that the whole Pi freezes and not only your program crashes ?

The "ps" command is similar to task-manager in windows.

List all running processes.

Code: Select all

ps -ef
Show running threads for a specific process.

Code: Select all

ps -Lf -p799

User avatar
joan
Posts: 15100
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How to monitor threads activities

Tue Oct 11, 2016 11:04 am

Use top, e.g.

top -u pi H

will show all threads used by user pi.

mfa298
Posts: 1386
Joined: Tue Apr 22, 2014 11:18 am

Re: How to monitor threads activities

Tue Oct 11, 2016 12:45 pm

paolojo wrote:Hi!
Could you suggest me a method to analize what are the threads that are runnig (something like "task manager" in windows)?
My python script launches simultaneously three thread every about five seconds. Each thread runs for about one second then he finishes his activities.
The problem is that after the script launches about 90 times the above theads, the raspy crashes.
My doubt is: probably the threads don't finish but remain in background causing CPU crash.
Could you help me?
Thanks a lot
Threads in things like Python and Ruby don't always equate directly to OS threads.

Sometimes the easiest way to see what's happening is to put lots of print statements into your code. Print out when threads start and exit and you should have some idea if what's happening.

If your script is running and then exiting then any threads it created should also stop (If you've started up external commands then they may not get killed by your script or the OS when the script finishes).

ewaller
Posts: 32
Joined: Tue Oct 04, 2016 5:24 pm

Re: How to monitor threads activities

Tue Oct 11, 2016 4:33 pm

joan wrote:Use top
Or, IMHO even better, htop

Return to “Troubleshooting”