Optimize game by detecting cpu usage, other apps or memory?

How I can optimize my game when a lot of apps are running in the background?
Can I somehow detect what is CPU usage or memory to give user some info to close other apps to make app more fluent.
When I close other apps in bg i have 60fps but when other are running my game is running 40-60fps and we have frame drops.

How to approach this problem?

There isn’t a portable way to do that across all platforms so you’re gonna have to write code for each specific platform to get memory/cpu usage at run time and it can cause performance issues in your app (unless you did it while the app is lunching and even with that there is no guarantees) so you might wanna consider a different approach for this particular problem any way if your still persistent about the way you wanna approche this then here they are some suggestions on how to do it for these platforms win|linux|mac

and here too

and if nothing worked out for you then you might wanna try setting your game framerate to 30fps instead of the unstable 60fps when there are background apps running.