Is the Windows Kernel Code still a Secret?

Given your username, I’m going to guess that the second post was made by your alter-ego during a psychotic break, or read directly from your mind by the forum software, which is controlled by the government/aliens/God.

Thats a possibility! :slight_smile:

The kernel is the core of the operating system. It does all of the things that many users aren’t even aware exists. You can think of it as kind of the “boss” of the system. The kernel handles things like task switching, memory allocation, and I/O device management.

Task Switching:

Let’s say you’ve got the dope running in one window, and you are listening to music in another program, and maybe you’ve got a document you are writing in the third window. To the user, these three things happen simultaneously. The computer can only do one thing at once, though. The kernel lets your web browser run for a tiny fraction of a second. Then it switches and lets the music program run for a tiny fraction of a second. Then it switches again and lets your word processor run. This is called “time slicing” since each program runs for a short slice of each second. To the user, all three programs are running at once, but in the computer, each one is running for a short amount of time.

It’s actually a bit more complicated than this, especially now that we have multi-threaded programs and multi-core processors, but that’s the basic idea.

Memory Allocation:

Your computer has a certain amount of RAM installed in it. Your web browser needs memory space so that it can store the data from web pages. Your music program needs memory space so it can store your song while it is playing it. Your word processor needs memory so that it can store the document you are writing. Each of these programs requests memory from the kernel, and the kernel looks at his great big list of free memory chunks and decides who gets what.

This is also a bit more complicated. What happens if your programs request more memory than your computer has? In the old days of computers, the computer would just give up and crash, but windows uses what is called “virtual memory”, which is fake memory. Windows basically lies to all of your programs. It says here’s a chunk of memory, and it starts with address XYZ, only the memory probably doesn’t actually start with address XYZ. When your program access memory location XYZ, it gets translated to the real memory offset without your program really being aware of it.

With a virtual memory system, when your programs ask for more RAM than your computer has, the kernel actually does give it to them, but it cheats. It sets aside space on your disk drive (called the “swap file”) and pretends that this is RAM. When a program accesses a chunk of RAM, it has to physically be located in the RAM chips. When a program tries to access RAM that windows has shoved onto the disk’s swap file, this causes a “page fault”, and the kernel takes a chunk of RAM and shoves it into the swap file to make a free spot in RAM, then takes the data that your program requested and shoves it into the free spot. Your program doesn’t realize that all of this swapping has occurred. As far as your program was concerned, it asked for a piece of memory and it got it. It doesn’t realize that windows actually had to stop everything, shift the data around, and then let the program run again.

All of this swapping takes time, so if your system is slow and you notice that your kernel is experiencing a lot of page faults, you might want to consider adding more RAM.

I/O devices:

I/O devices, like hard drives, USB ports, etc. all have device drivers associated with them. Device drivers are managed by the kernel. When you press a key on your keyboard, this triggers an interrupt. The kernel says ok, that’s interrupt X and it is handled by this device driver over here, and it executes that device driver (likely a PS/2 or USB keyboard driver, depending on your type of keyboard). The device driver will likely generate what is called a “signal”, which is sent out by the kernel. If your word processor is the active window at the time, it will receive the signal, and what you type appears on the word processor’s page.

I don’t know exactly where Windows draws its lines, but in a typical operating system, the user shell is actually a task. The user shell is the part that users think is “windows”. It’s the screen, the icons, the start menu, and all of that.

If you right click on your task bar at the bottom of the screen and select “task manager” you can see some of what the kernel is doing. The “applications” tab shows you what is running from a user’s point of view. If you click on “processes” you can see what actual processes are running. Some of your user programs will have multiple processes, and some processes will have multiple “threads”. An easy way to explain threads is if you have firefox running with multiple tabs. Each tab has its own web page, so you’ve got one program running (firefox) but it’s doing three things at once. Each window will get it’s own thread, and actually, it may get more than one, depending on what’s on the web page. On my system, if I click on the performance tap I can see that I have 73 tasks running, but 768 threads, so I’ve got an average of about ten threads for each program running.

The performance tab also shows you your page file usage. That’s your swap file.

The processes tab will also show you how many time slices each process is using, in terms of a percentage of total time slices available.

This may be bordering on technobabble for you, so if you need more explained, let me know and I’ll do the best that I can.

You’ve made an important point, especially in the world of globalization where other nations might not respect or marginally enforce copyrights and trade secrets.