Why is an OS with only a ready and running state inefficient? - operating-system

I'm studying for an operating systems exam and I cant think of a sufficient reason as to why the system would need more than two states. Could someone explain the reason further to me?
This is the question as its asked:

You would also want a 'waiting' state. When a process is waiting for some I/O input or input from another process, it would move to the waiting state and another process could run while it is waiting.
This might help you some: http://people.csail.mit.edu/rinard/osnotes/h6.html

What if a process wants or needs to sleep/delay/wait for some time/event?
Waiting for I/O to finish is a common example, which can be as simple as waiting for the next key press by the user or waiting for some client to connect over the network.

Related

Does Non-maskable interrupts effects processing of critical sections

My understanding is that a non-maskable interrupt enforces context switching (which causes a process to be moved from CPU to ready queue). If the interrupt happens at a time when the process is executing its critical section, it may make the output indeterministic. One solution is to roll back to the state when the process entered the critical section, but I don't know if that is possible. Please help clarify this. Thanks in advance!
If there would be a way that roll back would happen, I honestly do not know.
Yes, there is ways of doing so by software of course, the developer could implement guards in his/her code to check if there is an anomaly if so they are will repeat the process again to avoid the corrupted data.

PhantomJS not killing webserver client connections

I have a kind of proxy server running on a WebServer module and I noticed that this server is being killed due to its memory consumption.
Every time the server gets a new request it creates a child client process, the problem I see is that the process remains alive indefinitely.
Here is the server I'm using:
server.js
I thought response.close() was closing and killing client connections, but it is not.
Here is the list of child processes displayed on htop:
(Those process are even more, it is just a fragment of the list)
I really need to kill those processes because they are using all the free memory. Am I missing something?
I could simply restart the server, but the memory will still be wasted.
Thanks you !
EDIT:
The processes I mentioned before are threads and no independient processes as I thought (check this).
Every http request creates a new thread, and that's ok, but this thread is not being killed after the script ends.
Also, I found out that no new threads are created if the request handler doesn't run casper (I mean casper.run(..)).
So, new threads are created only if the server runs a casper instance, the problem is that this instance doesn't end after run function does.
I tried casper.done() as mentioned below, but it kill the whole process instead of the current running thread. (I did not find any doc for this function).
When I execute other casper scripts, outside the server in the same machine, the instanced threads and the whole phantom process ends successfully. What would be happening?
I am using Phantom 2.1.1 and Casper 1.1.1 versions.
Please ask me anything if you want more or specific information.
Thanks again for reading !
This is a well known issue with casper:
https://github.com/casperjs/casperjs/issues/1355
It has not been fixed by the casper guys and is currently marked as an enhancement. I guess it's not on their priority list.
Anyways, the workaround is to write a server side component e.g. a node.js server to handle the incoming requests and for every request run a casper script to do the scraping in a new child process. This child process will be closed when casper terminates it's job. While this is a workaround, it is not an optimal solution as the cost of opening a child process for every request is not cheap. it will be hard to heavily scale an approach similar to this. However, it is a sufficient workaround. More on this fully sensible approach is in the link above.

How to ping an application pool

We are trying to troubleshoot app pool hang scenarios, so one of the queue we thought of monitoring was http.sys queue.We need to check different parameters like app pool status and requests in queue.
Http.sys request queues are obtained from perfmon .Is there any way I can ping application pool and check status during each stage/requestload.
We are dealing this issue in two phases
1.Remove node out of HLB(we have script) once node is not responding or hung or slow, before end users complain( we get a lot of comlpaints)—priority 1
2.troubleshoot what’s the cause of hung—priority 2
Thanks in advance.
EDIT:
This article looks promising.But not able to find how to execute this.Any help on this please.
http://msdn.microsoft.com/en-us/library/ms691445(v=vs.90).aspx
I'm not sure an app pool's state will tell you if it is hung, just if it is started, stopped, or changing states.
I think you'll want to look at the IIS performance counters. I've never had to do anything like that, but the Get-Counter cmdlet is probably what you'll use.
Looks like there is another Stack Overflow question/answer that has some sample code:
Get-Counter "\\$ServerName\web service($SiteName)\current connections"):

simultaeous programs

I see that advantages or running programs simultaeously are that the user can run multiple programs and it offers better CPU usage, can any one give me an example of when it actually saves CPU time? eg busy waiting?
Not sure if I understand right, but when your emacs is waiting for you to type, you save time by scheduling another application while waiting for keyboard inputs.

How do I determine whether the user is waiting on a program?

We've got a requirement to determine whether the user is waiting on a program to do something. The biggest issue I see here is, if I monitor user activity (Keyboard and Mouse) then I'll assume the user is waiting when they might be reading, thinking, on the phone, etc.
Sometimes, if I know I'm going to have to wait a long time on a process (like booting up), I'll go get a coffee whilst it loads. I'm not really waiting on any one program, I'm just being efficient with my time.
I'm open to any ideas, even requesting the user use a key or key-combination to indicate they're waiting.
Is there a way to determine whether a user is waiting on a program?
Give the user the illusion that they could do the next step of interaction, i.e. don't tell them right away that the previous action has not completed. Then, when they try do something, you'll notice that they really would like to do something now and hence are waiting if they can't.
In some cases, you may find that what they want to do can actually be done right away, despite the previous action still being in progress.
You can't tell what a non-interacting user is doing. They could be day dreaming and you'd have no idea if they were waiting on the computer or not.
You might be able to deduce from user interaction that a user was waiting when you see no activity during a period of time when disk and or CPU usage is high. But this is not a scientific measure, it's merely an indicator. The assumption that the user was waiting negates the possibility to use the results for meaningful measurements.