Top Related Projects
The FreeBSD src tree publish-only repository. Experimenting with 'simple' pull requests....
Read-only git conversion of OpenBSD's official CVS src repository. Pull requests not accepted - send diffs to the tech@ mailing list.
A free Windows-compatible Operating System
An open-source Unix operating system
WDF makes it easy to write high-quality Windows drivers
Quick Overview
The torvalds/linux repository is the official kernel source tree for the Linux operating system. It contains the core code that manages hardware resources, provides essential services, and serves as the foundation for all Linux distributions. This repository is maintained by Linus Torvalds and a large community of developers.
Pros
- Open-source and freely available, allowing for widespread adoption and customization
- Highly stable and secure, with frequent updates and patches
- Supports a vast array of hardware architectures and devices
- Large and active community of developers and contributors
Cons
- Complex codebase that can be challenging for newcomers to understand and contribute to
- Kernel development requires specialized knowledge and skills
- Some hardware manufacturers do not provide open-source drivers, leading to compatibility issues
- Rapid development cycle can sometimes introduce regressions or compatibility problems
Code Examples
As the Linux kernel is not a code library but an operating system kernel, providing code examples in the traditional sense is not applicable. However, here are a few examples of kernel-related code snippets:
- A simple kernel module:
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void)
{
printk(KERN_INFO "Hello, World!\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_INFO "Goodbye, World!\n");
}
MODULE_LICENSE("GPL");
This code demonstrates a basic kernel module that prints messages when loaded and unloaded.
- A system call implementation:
SYSCALL_DEFINE2(example_syscall, int, arg1, char __user *, arg2)
{
char kernel_buf[256];
long ret;
ret = strncpy_from_user(kernel_buf, arg2, sizeof(kernel_buf));
if (ret < 0)
return ret;
printk(KERN_INFO "Example syscall called with arg1=%d, arg2=%s\n", arg1, kernel_buf);
return 0;
}
This code shows how a simple system call might be implemented in the kernel.
- A device driver skeleton:
#include <linux/module.h>
#include <linux/fs.h>
static int device_open(struct inode *inode, struct file *file)
{
// Device open implementation
return 0;
}
static ssize_t device_read(struct file *filp, char __user *buffer, size_t length, loff_t *offset)
{
// Device read implementation
return 0;
}
static struct file_operations fops = {
.read = device_read,
.open = device_open,
};
static int __init example_init(void)
{
// Driver initialization
return 0;
}
static void __exit example_exit(void)
{
// Driver cleanup
}
module_init(example_init);
module_exit(example_exit);
MODULE_LICENSE("GPL");
This code provides a basic structure for a character device driver in the Linux kernel.
Getting Started
As the Linux kernel is not a typical software library, there isn't a traditional "getting started" guide. However, here are some steps to begin working with the kernel source:
-
Clone the repository:
git clone https://github.com/torvalds/linux.git
-
Install necessary build tools (on Ubuntu):
sudo apt-get install build-essential libncurses-dev bison flex libssl-dev libelf-dev
-
Configure the kernel:
make menuconfig
-
Build the kernel:
make -j$(nproc)
-
Install modules:
sudo make modules_install
-
Install the kernel:
sudo make install
Note that kernel development requires advanced knowledge and caution, as mistakes can lead to system instability.
Competitor Comparisons
The FreeBSD src tree publish-only repository. Experimenting with 'simple' pull requests....
Pros of FreeBSD
- More permissive license (BSD) allowing for broader use in commercial products
- Unified development of kernel and userland, leading to better integration
- Simpler and more consistent codebase, easier for newcomers to understand
Cons of FreeBSD
- Smaller developer community, potentially slower development pace
- Less hardware support, especially for newer devices
- Fewer third-party applications and drivers available
Code Comparison
FreeBSD (kernel initialization):
void
mi_startup(void *dummy)
{
struct timeval boottimer, dummytv;
void *startkernel;
char *v;
Linux (kernel initialization):
asmlinkage __visible void __init start_kernel(void)
{
char *command_line;
char *after_dashes;
set_task_stack_end_magic(&init_task);
Both snippets show the entry point for kernel initialization, but FreeBSD's approach appears slightly simpler and more straightforward. Linux's initialization process involves more complex setup steps from the beginning, reflecting its broader hardware support and feature set.
Read-only git conversion of OpenBSD's official CVS src repository. Pull requests not accepted - send diffs to the tech@ mailing list.
Pros of OpenBSD
- Stronger focus on security and code auditing
- Cleaner, more consistent codebase
- Stricter licensing (ISC license)
Cons of OpenBSD
- Smaller developer community and ecosystem
- Limited hardware support compared to Linux
- Slower adoption of new features and technologies
Code Comparison
Linux kernel (simplified example):
struct task_struct {
volatile long state;
void *stack;
atomic_t usage;
unsigned int flags;
// ... many more fields
};
OpenBSD kernel (simplified example):
struct proc {
TAILQ_ENTRY(proc) p_list;
struct process *p_p;
TAILQ_HEAD(,filedesc) p_fd;
// ... fewer fields, more focused
};
The Linux kernel's task_struct
is more complex and feature-rich, while OpenBSD's proc
structure is simpler and more focused on core functionality. This reflects the different design philosophies of the two projects, with Linux aiming for broader compatibility and feature set, while OpenBSD prioritizes simplicity and security.
Both projects are open-source Unix-like operating systems, but they cater to different use cases and priorities. Linux is more widely adopted and offers greater flexibility, while OpenBSD is often chosen for its security-focused approach and clean codebase.
A free Windows-compatible Operating System
Pros of ReactOS
- Aims to be binary-compatible with Windows, allowing users to run Windows applications
- Smaller codebase, potentially easier for new contributors to understand and modify
- Focuses on desktop and server environments, potentially more user-friendly for those familiar with Windows
Cons of ReactOS
- Significantly smaller developer community and less frequent updates
- Limited hardware support compared to Linux's extensive driver ecosystem
- Less mature and stable, with fewer real-world deployments
Code Comparison
ReactOS (system call example):
NTSTATUS NTAPI NtCreateFile(
PHANDLE FileHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
PIO_STATUS_BLOCK IoStatusBlock,
PLARGE_INTEGER AllocationSize,
ULONG FileAttributes,
ULONG ShareAccess,
ULONG CreateDisposition,
ULONG CreateOptions,
PVOID EaBuffer,
ULONG EaLength)
Linux (system call example):
SYSCALL_DEFINE3(open, const char __user *, filename, int, flags, umode_t, mode)
{
return do_sys_open(AT_FDCWD, filename, flags, mode);
}
Both projects implement system calls, but ReactOS follows Windows API conventions, while Linux uses its own system call interface.
An open-source Unix operating system
Pros of illumos-gate
- More advanced ZFS implementation with features like native encryption
- Better support for virtualization through Zones (lightweight containers)
- Stronger focus on observability with DTrace integration
Cons of illumos-gate
- Smaller community and ecosystem compared to Linux
- Less hardware support and driver availability
- Fewer available applications and packages
Code Comparison
illumos-gate (OpenSolaris-derived):
void
kmem_cache_free(kmem_cache_t *cp, void *buf)
{
kmem_slab_t *sp;
if (buf == NULL)
return;
Linux:
void kmem_cache_free(struct kmem_cache *cachep, void *objp)
{
unsigned long flags;
cachep = cache_from_obj(cachep, objp);
if (!cachep)
return;
Both snippets show memory management functions, but illumos-gate uses a slightly different naming convention and structure. The Linux version includes additional error checking and uses a cache_from_obj function to verify the cache.
WDF makes it easy to write high-quality Windows drivers
Pros of Windows-Driver-Frameworks
- More focused scope, specifically for Windows driver development
- Easier to get started for Windows-specific driver projects
- Better integration with Microsoft development tools and ecosystems
Cons of Windows-Driver-Frameworks
- Limited to Windows platform, less versatile than Linux
- Smaller community and fewer contributors compared to Linux
- Less frequent updates and potentially slower bug fixes
Code Comparison
Windows-Driver-Frameworks:
NTSTATUS
DriverEntry(
_In_ PDRIVER_OBJECT DriverObject,
_In_ PUNICODE_STRING RegistryPath
)
{
// Windows driver initialization code
}
Linux:
static int __init my_init(void)
{
// Linux kernel module initialization code
return 0;
}
module_init(my_init);
The code snippets show the entry points for a Windows driver and a Linux kernel module, respectively. Windows-Driver-Frameworks uses the DriverEntry
function, while Linux uses the module_init
macro with a custom initialization function.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Linux kernel
There are several guides for kernel developers and users. These guides can be rendered in a number of formats, like HTML and PDF. Please read Documentation/admin-guide/README.rst first.
In order to build the documentation, use make htmldocs
or
make pdfdocs
. The formatted documentation can also be read online at:
https://www.kernel.org/doc/html/latest/
There are various text files in the Documentation/ subdirectory, several of them using the reStructuredText markup notation.
Please read the Documentation/process/changes.rst file, as it contains the requirements for building and running the kernel, and information about the problems which may result by upgrading your kernel.
Top Related Projects
The FreeBSD src tree publish-only repository. Experimenting with 'simple' pull requests....
Read-only git conversion of OpenBSD's official CVS src repository. Pull requests not accepted - send diffs to the tech@ mailing list.
A free Windows-compatible Operating System
An open-source Unix operating system
WDF makes it easy to write high-quality Windows drivers
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot