Software Interrupt
What I've learned so far: An OS may trigger a software interrupt by executing a system call. According to what I read online, this is implemented via special instructions such as INT that the CPU can execute. I also understand how interrupts get handled by the interrupt service routine.
My question: since the CPU can only execute one instruction at a time, how does it work? For example, lets say a program X was hogging the CPU resources. The OS would have to execute a software interrupt to regain control of the CPU, but how would it do this (since the CPU is already executing instructions)?
Thanks for any explanations.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
A real pre-emptive OS would need a clock interrupt (from the outside world) to function.
This would be capable of interrupting "while(1);" and give control back to the OS to decide on something else to do.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
I get the concept, I just don't understand specifics of how it happens. I'm thinking a possible exam question on my OS test would be something like "what is a system call and how does it work". I can answer the first part, but not the second part. And when you say "from the outside world" that sounds like... a hardware interrupt?
edit:
I just found something that I think will help: something called the "time quantum" and the timer interrupt handler for Linux. It says once the time quantum expires, the process gets preempted... which is something like what I'm looking for, so I think it'll yield some answers. Consider this solved for now, and thanks for the help Salem.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
This is conceptually wrong. It is an application which does a software interrupt to enter into OS.
My book says there are 3 ways to switch from user mode to kernel mode: an interrupt, a trap, and a system call. Since an interrupt can be only done through hardware, and since my book says a trap is a 'software generated interrupt', which is the same thing it says for a system call . . what does the kernel do if a user application simply refuses to relinquish control of the CPU (as in Salem's case of while(1))? It would seem that the kernel cannot do anything in this case.
edit: I understand the info you've said to me, as I've been reading about that in my book at the same time. The OS has system calls made available so that user programs can ask for services that they otherwise wouldn't be privy to. But it still doesn't answer the question of 'what happens when a process refuses to give up the CPU'.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
Because the user level application should not have access to the same data and services that the OS does. Hence the OS provides services to the user level application via system calls.
But are you telling me there is no mechanism by which the OS regains control of the CPU if a user application attempts to hog it and not give it back? I wouldn't be so persistent, except that my professor alluded to as much in class. I just haven't been able to figure out what that mechanism is. Of course, the OS could always wait for an application to make a system call, or otherwise wait for an interrupt from I/O etc... but if no such interrupt occurs, the OS should still have a method by which it can regain control of the CPU.
Either way, thanks for your help, you've been helpful clarifying some concepts that were getting a little jumbled in my head.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
Well I appreciate all the info, again, it was helpful in clarifying a few things that I wasn't clear on previously. I finally found the info I was looking for; apparently there is a timer which the OS can schedule which will automatically interrupt any process which runs over its time slice.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
Interesting.....
Scroll up....
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Yeah, I see that now. I don't know why but I didn't connect the dots until you said that just now. But thanks again for the responses.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354