linux kernel step by step [closed] - c

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
i know c language.my goal is to read linux kernel.so what languages should i learn(write books too) before start reading kernel and is there any book to help reading linux kernel

This book is a little outdated, but Understanding The Linux Kernel is an amazing reference. It will also give you a crash course in i386 features that make a lot of the kernel facilities possible (such as the MMU and how interrupts work. With operating systems, it's sometimes hard to understand where the hardware ends and the OS begins), and reference a lot of the critical source directly.
Also, look into the LWN Kernel article index for more up-to-date references.
One good way to start is come up with a really simple feature that you'd like to add to the kernel and start hacking away at it. (Something I did in college was count how many times each process got preempted and export that value via the /proc file system. Taught me a lot about scheduling, /proc, the process structure, and many other facilities). Also a recommendation, do this in a VM unless you plan to reboot every fifteen minutes.
For ad hoc questions, searching Google works, or asking questions on IRC. (Respectfully, of course.)

The Linux kernel is over 11.5 million lines long! It takes years to be a good programmer and you have to be one if you want to hack the Linux kernel. Taking your age and experience into account, you will most probably fail if you make that your first C project. I recommend getting your hands wet on some other cool stuffs using C. For Example, port the codes in the GreyHat Python book (debuggers, hooking, fuzzing and e.t.c) to C and add interesting features to them. If you are really into OS development, I recommend reading good books on Assembly and writing your own little real time OS. I've seen a real time OS written by a 13 year old kid so it's possible. Good luck!

Not so long ago there was a Linux kernel workshop at Hackerspace Brussels. You can take a look at the links on the event page https://hackerspace.be/LinuxKernelWorkshop

I raised this question myself years ago. I've then got stuck into lines of Linux kernel source code to figure out how it works. Till now my understanding on Linux kernel is still a mix. I think the best way to understand a program is write it by yourself. To build an OS, I think this is the minimum:
computer hardware & architecture
assembler & compiler
assembly
C language
There are lots of books out there that could help you read Linux kernel piece by piece. You still have a lot of time to rewrite it yourself.

Related

Windows programmer moving to linux - Coding conventions [closed]

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
I have been developing for Windows for a long time, mainly WinApi (and .Net).
I'v started learning basic Linux, and I have some questions regarding the differences:
In Windows I have barely used the C Standard library.
If I needed an API, I would search MSDN and find the appropriate library\function.
From what it seems like, in Linux the C Standard library is EVERYTHING.
All the code samples I have seen used the standard library (Instead of using some Linux internal functions, like a Linux "CreateFile").
Is this really how writing "proper" linux code is done ? Using the C standard library ?
If I wish to read a file, or allocate memory are fopen\malloc the way to go ?
If the answer to my first question is yes (And I guess it will be)
The C standard library is POWERLESS compared to the powerful WinApi.
Lets say I wish to get a list of running process (CreateToolhelp32Snapshot) or create a thread or a process (CreateThread\CreateProcess), How should I do that in Linux ?
Documentation.
In Windows, all I need can be found in MSDN.
If I have a "how do I do" question (Like the questions above) where should I go ?
Where is my main source of documentation.
Thanks a lot,
Michael.
Perhaps you've forgotten that the Standard C Library isn't environment-specific, it specifies least-common-denominator functionality among all systems that can run C programs, and C runs on systems that don't even have processes.
If you want an API that provides consistent common GUI/multithread/etc. APIs, pick a likely-looking GUI/multithread/etc. API. You might start with Qt, it's quite comprehensive and produces good-looking, near-native UIs on a host of systems.
It's not generally considered polite to point this out, but most questions that get asked publicly are asked by people who lack the discipline to do even simple research. Once people can do that, they don't need to ask very many, and that's why what you see is so ... trivial. You're past that. For more options, you could start here.
For more general-purpose tools, the top hit on a search for important linux tools might be helpful.

Which Linux distro uses Linux kernel as is with no modification [closed]

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'm trying to do some learning with Linux kernel and as you all know there is nothing better than playing with the code itself, Can you please let me know which one of the Linux distros is the easiest to work with? In other words, As far as I know Ubuntu for example modify the kernel for their distro, so the question again, which distro is using the Linux kernel as is with no modification?
Appreciate your guidance.
When it comes to no-frills (no external patches to the kernel) have a look at Slackware. Or follow "Linux from Scratch", that's as bare-bones as it gets.
If you want to start playing with the Linux kernel, I'd recommend a distribution which makes it particularily easy to compile the kernel yourself. Although I cannot provide detailed guidance, Gentoo seems to do so (although gentoo has other drawbacks, I don't know a single person in real life who actually used gentoo for more than two years).
I would not try and look for distributions not modifying the kernel, it's probably not worth the effort. Patches will probably be minor compared to the overall size of the kernel.
You can easily run Ubuntu for example with a vanilla kernel by following https://wiki.ubuntu.com/KernelTeam/GitKernelBuild.

LInux vs BSD for kernel development [closed]

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 11 years ago.
Improve this question
I recently updated my rusty C skills, and I've been trying to find a project to try them out on, so I picked kernel development (after all, C is a systems language). So, I was wondering which would be easier to start out with, Linux or one of the BSDs? Linux has a larger userbase (so I would probably have more support), but it also has a humongous codebase (9 million lines last time I checked), would the BSDs be easier to start out with because they combine the userbase and kernel into one large codebase? Also, is it best to just start reading the kernel source code? And, are they trying to implement new features aside from SMP and new drivers?
Unfortunately, I can only speak of Linux kernel hacking for myself. Currently I'm in an internship where I am working on a kernel, and I never did this before. But I was able to learn a lot of stuff in a quite short time, due to several reasons (again, I want to point out that I don't know how much of this is covered withint he BSD community):
Tutorials. The Linux Community is quite big and therefore you will find a lot of beginners information on kernel hacking. I feel like the standard to begin with was this guide. If you read it you will see, that even kernel hacking starts with hello world ;)
Linux Cross Reference. A great tool. It covers the complete Vanilla source code and shows you where each function/struct/define/whatever was defined and implemented, so no long searching for some stuff
The modular build of linux (I assume the same goes for BSD) Clearly you won't be able to look through 9 mio lines of code. But you can start easy with a little loadable kernel module and then go deeper. Maybe look at other modules first, hack them, and finally dig into the directly compiled stuff
The sheer community size. Not only kernel mailing lists, but also a huge number of forums or Q&A sites like this one where you can be sure to get help if you don't know what to do ;)
Just my 2 cents ;)
I am using and developing for Linux for many years, but am lacking any real experience with BSD to recommend either way.
You sound lacking experience for kernel hacking. Just reading kernel source might be insightful, but won't really teach you much. There is a lot going on in Linux kernel besides drivers. For example, latest 2.6.38 was focused on desktop responsiveness. DRM stack is ever changing and could use more man power.
I'd suggest start easy, small fixes for beta drivers, etc.

Resources for learning C, Unix, Linux and embedded systems [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I want to learn C , UNIX and LINUX, and more about embedded systems. Very much interested in them. Are there any online courses or websites which can guide me. And please suggest books to read in learning them.
Thanks for your time.
Ya please lets your answers and comments come in , they are invaluable to me..!!
The C Programming Language by K & R
Advanced UNIX Programming
UNIX Network Programming
Structure and Interpretation of Computer Programs Videos (done in LISP, but invaluable programming course)
Understanding the Linux Kernel (a little out of date but good info, don't take as gospel)
Linux Device Drivers 3rd Edition (pretty out of date but good info, same as above)
Writing Linux Device Drivers (pretty up to date but not as detailed as before)
The UNIX Time-Sharing System, this is essentially the original UNIX paper, it may help to understand where all this came from, don't have to understand every detail of this old paper but I think it gives some good background
I'd highly recommend "UNIX for dummies" as a starting point on Unix/Linux.
There are many amazing resources online. My favorite is from MIT.
http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/
Free courses. They can be pretty in depth, and cover many more subjects than just computer science and mathematics.
Few resources that helped me for C:
The C Programming Language Book by K & R
highercomputingforeveryone.com helped me out initially
Stanford's Programming Paradigm Videos
Good Luck!
A quick way to learn a bit about all of the above is to buy an MSP430-based development board from Texas Instruments, install mspgcc (the open-source compiler for the MSP430) on a Linux machine, and write a basic C program that blinks an LED on the development board.
Other than the resources suggested above, you need to understand why you need these languages. Programming language or an OS alone will only take you as far -- for e.g. if you are programming on embedded platforms usually memory is not in abundance. So you need to code for memory optimization. If you are working on real time, you would need to understand interrupt handling well etc. I'd suggest definitely spend time on the architecture (ARM Cortex-M1 etc) for which you are planning to code. Always helps.
For more quirks look into http://en.wikibooks.org/wiki/Embedded_Systems/C_Programming
Orielly's Programming Embedded Systems in C and C++ is a good place to start once you have the basics of C/C++ clear.

How should I get started on writing device drivers? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I would like to learn how to write device drivers because I think it would be fun. I use a Mac OS X Macbook, but I also have an Ubuntu machine (running on a Mac Min). I am pretty familiar with C and currently am reading this book. I have found some links online such as Mac Dev Center. I am doing this because it would be fun. I think there would be real gratification to see hardware operate because of software I wrote.
I guess what I would like is some tips or advice and guidance, and does anyone know of a list of devices that don't have drivers or can I write a driver for something that's already supported (would prefer the former so I'm actually providing value). What's a good device to get started with? Am I biting off more than I can chew? I'm not afraid of low level programming or assembly or whatever amount of effort is required. I'd like a challenge really!
For Linux, you might look into picking up the O'Reilly Linux Device Drivers book or reading PDFs online. In my opinion, it is one of the better texts around on the subject.
The Linux Kernel Module Programming Guide is another good resource.
You may also want to pick up a book specifically on the Linux Kernel. I picked up a copy of Robert Love's Linux Kernel Development (2nd Edition) for this purpose (3rd Edition on the way).
Writing a device driver can be pretty simple, or it can be almost arbitrarily complicated. For instance, I've been involved in a project where it took six of us almost three years to solve ONE bug in a device driver. Of course, we cleared out dozens of other bugs while looking for it... the code improved immensely. The fix turned out to be an eight line patch, that cost, conservatively, about a million dollars.
But, as a side project to that, I wrote an ethernet driver from the chip data sheet in a week, and took another week to debug it. Haven't needed to touch it since.
There's no way to say in general how much work a driver will be; a GPU driver could cost hundreds of millions, a driver for a single LED costs a couple of hours work at the most.
If you want to go for Linux device driver development, the freely available O'Reilly book Linux Device Drivers, Third Edition is a must read.
In order to find unsupported hardware pieces for which you could write a driver, ask on the Linux mailing lists. Maybe some USB 3.0 device? ;)
For Mac you might want to take a look at Mac OS X Internals book. It's think and heavy but fun to read. It is mostly about PowerPC-based Macs but has an appendix about Intel-based ones. For Linux take a look at Linux Device Drivers, 3rd Edition - it's lighter (free PDFs online :) and is really device driver-oriented, might be a better start.

Resources