Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
How can we give a process in taskmanager (like notepad.exe) as an input as process for my Bankers Algorithm (Deadlock detection) ???
It's going to be hard and probably unfeasible to keep track of all the OS / external conditions to implement a real deadlock-prevention algorithm on a real application. Modern OSes (when we're not talking about RT-aware systems) prefer not to implement such algorithms due to their overwhelming complexity and expensiveness.
In other terms you can get away from a Windows deadlock, in the worst case, with a simple reboot. And given how many times this happens it isn't deemed a huge problem in the desktop OSes market.
Thus I recommend to write a simple test case with a dummy application that will either
Serve your purpose
Allow you to know exactly what's being used by your application and let you manage the complexity
As a sidenote: applications like notepad.exe or similar are not real-time processes even if you give them "Real Time" priority in the Windows task manager (and not even soft-real time). Real real-time processes have time constraints (i.e. deadlines) that they MUST observe. This isn't true in any desktop OS since they're just built with a different concept in mind (time sharing). Linux has some RT patches (e.g. Xenomai) to render the scheduling algorithm in the kernel a real real-time one, but I'm not aware of the status of that patch right now.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Question Is there an API for Windows and/or Linux that will let me find out which processes are draining battery?
A few notes:
It doesn't have to be precise, I'd be ok with only three levels (low energy cost/fair energy cost/high energy cost) if that's all I can get.
I already have CPU load information, that's not what I am looking for, as experience shows that processes with very low CPU use can nevertheless drain battery by having high I/O, high swapping or frequent wakeups. This is why I'd like to piggyback on whatever the OS is already using: OS developers are much more likely than me to have actually tested this.
I found a partial solution for macOS. See answers.
MSDN doesn't seem to indicate any energy-related API.
I cannot request admin/root rights for running my task manager, so I cannot simply parse the syslogs looking for power usage alerts.
I've found a great reference for how macOS does it.
https://blog.mozilla.org/nnethercote/2015/08/26/what-does-the-os-x-activity-monitors-energy-impact-actually-measure/
That should be fairly easy to follow.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am a hobby programmer interested in dynamic systems like game engines etc. and I had the Idea of a task scheduling system using something like a priority queue to sort different tasks dynamically and maybe include a parallel feature to use multiple cores efficiently. My explicit idea was to use some kind of Task class that itself stores a function pointer and two queue parameters, one being the gravity of the task and one being the time since it was pushed onto the queue, which then would be multiplied to archieve the position in the listing.
Now here comes my question. Would such a system be more efficient in general or at least pay up in any way in comparisation to a hard-coded system (like some 'main loop')?
e.g. is it a better solution / is it faster?
Thanx for the replies.
This is exactly what priority queue's where designed for. Start your design with priority queues and see how well it goes. Then you may want to tweak it if specific issues come up.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Let's say I have a vector of exact future times of multiple events. I want those events to launch when their respective times have been reached. How do I do this without constantly using if statements to check that the current time is one of those set times? This constant checking, especially if many other things are running in my program (and some of those times may be a bit away from now) will reduce the performance of my program. I'm using c++11, latest version of GCC.
If you're using C++11, it's probably easiest to create a thread, have it sleep until the next alarm time. The most efficient way to store the times for the alarms is probably a priority queue.
If you don't have C++ 11 available, you might consider Boost Threads instead. The standard's threads are based closely on Boost threads, so using them will be fairly similar.
If you don't want to use that, you'll pretty much need to use operating system facilities to do the job. With almost any reasonably modern OS, you can create a thread and have it sleep until the next alarm time, but you'll probably also have something that supports what you want a little more directly (call a function at a specified time). The details of that will be specific to the OS though.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
i'm learning c/c++ and i'm wondering if it is possible to detect a process by it's name and kill it when it's cpu/memory usage exceed a certain value. I would apreciate any help with the actual code or just pointing me in the right direction.
In recent versions of Windows, you can ask the OS to take care of this for you -- create a Process Job Object and configure limits. The accounting features of the job object will let you track resource usage.
In Linux/Unix you would use ulimit.
Don't try to enforce this yourself. If you have a runaway process, the most likely scenario is that your enforcer won't be scheduled in a timely manner to kill it. You really want help from the kernel, and in particular the thread scheduler.
For Windows and c++:
Memory Usage
Check out GetProcessMemoryInfo. There's also an example at msdn.
The GetProcessMemoryInfo() function will provide you a pointer to a PROCESS_MEMORY_COUNTERS struct which contains all of the memory usage information.
CPU Usage
For CPU usage it's a little bit more difficult but the following stackoverflow question is related to that: Getting current cpu usage in c++/windows for particular process
You need to create a process to monitor your other processes.
To do this in Linux in c++:
You can read from /proc/stat directly, or create a process to run 'ps' and parse its output to find processes with high %cpu. To create a process that runs ps, you'll need to use the 'fork' command.
Then you can call 'execvp' to call 'kill ', a function from .
Same idea goes for the bash script (this is probably quite a bit easier though).
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I need some library which has comprehensive set of APIs which can help to collect performance data of current machine. Could be very useful if this library written in C++ or Perl.
Tried to googling, since I don't know right terminology for that I found a lot of big and already established projects, which I cannot embed into my code.
What you are looking for is called PAPI Performance Application Programming Interface. It lets you collect data on all performance counters available e.g. FLOP (floating point operations) if you wish to validate your theoretical FLOP count. It also offers an API to compute MFLOPS or even find the cache hit ratio for your application. I have used the library extensively in supporting platforms in addition to Intel VTune.
Here is a list of "native" PAPI events but everything else you will find as CPU native counters.