Jump to content

Finding memory leaks of software using the top command

Hello, I went to an interview and the interviewer asked me "what command can be used to check running processes in linux?". The top command came to my mind so I told him that. He then asked me "using top command, how is it possible to find a memory leak of an application". I wasnt very sure about the answer but I told him that, "using the top command it will be possible to see a closed process still running and using the allocated memory which can be a sign of a memory leak". He then replied there is a specific top command that can show a memory leak. I didnt know the answer to this question. I came home and had a look online for a top command that showed memory leaks, but didnt see a specific command. If you know the answer to this, please do share it with me so I can improve my knowledge. Thank you.

Link to comment
Share on other sites

Link to post
Share on other sites

do you even know what memory leak is?

mY sYsTeM iS Not pErfoRmInG aS gOOd As I sAW oN yOuTuBe. WhA t IS a GoOd FaN CuRVe??!!? wHat aRe tEh GoOd OvERclok SeTTinGS FoR My CaRd??  HoW CaN I foRcE my GpU to uSe 1o0%? BuT WiLL i HaVE Bo0tllEnEcKs? RyZEN dOeS NoT peRfORm BetTer wItH HiGhER sPEED RaM!!dId i WiN teH SiLiCON LotTerrYyOu ShoUlD dEsHrOuD uR GPUmy SYstEm iS UNDerPerforMiNg iN WarzONEcan mY Pc Run WiNdOwS 11 ?woUld BaKInG MY GRaPHics card fIX it? MultimETeR TeSTiNG!! aMd'S GpU DrIvErS aRe as goOD aS NviDia's YOU SHoUlD oVERCloCk yOUR ramS To 5000C18

 

Link to comment
Share on other sites

Link to post
Share on other sites

57 minutes ago, Levent said:

do you even know what memory leak is?

incorrect management of memory? Like a program not releasing the allocated memory that it was using even after it has been closed.

Am i correct?

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Shammikit said:

incorrect management of memory? Like a program not releasing the allocated memory that it was using even after it has been closed.

Am i correct?

no that is not what memory leak is.

mY sYsTeM iS Not pErfoRmInG aS gOOd As I sAW oN yOuTuBe. WhA t IS a GoOd FaN CuRVe??!!? wHat aRe tEh GoOd OvERclok SeTTinGS FoR My CaRd??  HoW CaN I foRcE my GpU to uSe 1o0%? BuT WiLL i HaVE Bo0tllEnEcKs? RyZEN dOeS NoT peRfORm BetTer wItH HiGhER sPEED RaM!!dId i WiN teH SiLiCON LotTerrYyOu ShoUlD dEsHrOuD uR GPUmy SYstEm iS UNDerPerforMiNg iN WarzONEcan mY Pc Run WiNdOwS 11 ?woUld BaKInG MY GRaPHics card fIX it? MultimETeR TeSTiNG!! aMd'S GpU DrIvErS aRe as goOD aS NviDia's YOU SHoUlD oVERCloCk yOUR ramS To 5000C18

 

Link to comment
Share on other sites

Link to post
Share on other sites

Pretty sure you are suppose to answer you actually can't do this with top..... 

If you are looking for unreap zombie child proccess then perhaps top may help a bit. That is not really memory leakage though. 

 

You need to use Valgrind or any other memory analysis tool.

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

If you want to test your application for memory leaks, use Valgrind. This command should get you started: valgrind --error-limit=no --read-var-info=yes --log-file=[output file] [executable]

Where

  • [output file] is the name you want to give the log file Valgrind reports to
  • [executable] is the name of the app you want to check

Note that running Valgrind with these options will make the app run slower. Also, make sure to build the app with debug symbols if possible.

Link to comment
Share on other sites

Link to post
Share on other sites

9 hours ago, Shammikit said:

incorrect management of memory? Like a program not releasing the allocated memory that it was using even after it has been closed.

Am i correct?

A memory leak happens when a program allocates memory and doesn't free it when it's no longer needed, meaning that eventually it will fill all your memory for no reason. I don't think there's a top command to detect a memory leak (you can read the man page for yourself, I may have missed it) but you could use it to spot programs that are using an abnormally large amount of memory.

 

By the way, for running processes you should probably have mentioned ps first.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

6 hours ago, Mira Yurizaki said:

If you want to test your application for memory leaks, use Valgrind. This command should get you started: valgrind --error-limit=no --read-var-info=yes --log-file=[output file] [executable]

Where

  • [output file] is the name you want to give the log file Valgrind reports to
  • [executable] is the name of the app you want to check

Note that running Valgrind with these options will make the app run slower. Also, make sure to build the app with debug symbols if possible.

While this is absolutely correct, valgrind isn't a standard Linux command so I doubt that's what the interviewer was looking for.

Don't ask to ask, just ask... please 🤨

sudo chmod -R 000 /*

Link to comment
Share on other sites

Link to post
Share on other sites

On 1/30/2020 at 2:05 AM, Sauron said:

While this is absolutely correct, valgrind isn't a standard Linux command so I doubt that's what the interviewer was looking for.

 

He wanted to hear "ps" in the first place and then, the follow-up answer would have been something like "ps ax -o pid,%mem,command".

 

But the interviewer obviously didn't know "top" and its default display columns (or even write the questions).

"top -o %MEM" is a convenience feature, usually not essential.

 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×