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 -- this is a read-only mirror of the official repository at https://code.illumos.org/plugins/gitiles/illumos-gate
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 -- this is a read-only mirror of the official repository at https://code.illumos.org/plugins/gitiles/illumos-gate
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
The Linux kernel is the core of any Linux operating system. It manages hardware, system resources, and provides the fundamental services for all other software.
Quick Start
- Report a bug: See Documentation/admin-guide/reporting-issues.rst
- Get the latest kernel: https://kernel.org
- Build the kernel: See Documentation/admin-guide/quickly-build-trimmed-linux.rst
- Join the community: https://lore.kernel.org/
Essential Documentation
All users should be familiar with:
- Building requirements: Documentation/process/changes.rst
- Code of Conduct: Documentation/process/code-of-conduct.rst
- License: See COPYING
Documentation can be built with make htmldocs or viewed online at: https://www.kernel.org/doc/html/latest/
Who Are You?
Find your role below:
- New Kernel Developer - Getting started with kernel development
- Academic Researcher - Studying kernel internals and architecture
- Security Expert - Hardening and vulnerability analysis
- Backport/Maintenance Engineer - Maintaining stable kernels
- System Administrator - Configuring and troubleshooting
- Maintainer - Leading subsystems and reviewing patches
- Hardware Vendor - Writing drivers for new hardware
- Distribution Maintainer - Packaging kernels for distros
For Specific Users
New Kernel Developer
Welcome! Start your kernel development journey here:
- Getting Started: Documentation/process/development-process.rst
- Your First Patch: Documentation/process/submitting-patches.rst
- Coding Style: Documentation/process/coding-style.rst
- Build System: Documentation/kbuild/index.rst
- Development Tools: Documentation/dev-tools/index.rst
- Kernel Hacking Guide: Documentation/kernel-hacking/hacking.rst
- Core APIs: Documentation/core-api/index.rst
Academic Researcher
Explore the kernel's architecture and internals:
- Researcher Guidelines: Documentation/process/researcher-guidelines.rst
- Memory Management: Documentation/mm/index.rst
- Scheduler: Documentation/scheduler/index.rst
- Networking Stack: Documentation/networking/index.rst
- Filesystems: Documentation/filesystems/index.rst
- RCU (Read-Copy Update): Documentation/RCU/index.rst
- Locking Primitives: Documentation/locking/index.rst
- Power Management: Documentation/power/index.rst
Security Expert
Security documentation and hardening guides:
- Security Documentation: Documentation/security/index.rst
- LSM Development: Documentation/security/lsm-development.rst
- Self Protection: Documentation/security/self-protection.rst
- Reporting Vulnerabilities: Documentation/process/security-bugs.rst
- CVE Procedures: Documentation/process/cve.rst
- Embargoed Hardware Issues: Documentation/process/embargoed-hardware-issues.rst
- Security Features: Documentation/userspace-api/seccomp_filter.rst
Backport/Maintenance Engineer
Maintain and stabilize kernel versions:
- Stable Kernel Rules: Documentation/process/stable-kernel-rules.rst
- Backporting Guide: Documentation/process/backporting.rst
- Applying Patches: Documentation/process/applying-patches.rst
- Subsystem Profile: Documentation/maintainer/maintainer-entry-profile.rst
- Git for Maintainers: Documentation/maintainer/configure-git.rst
System Administrator
Configure, tune, and troubleshoot Linux systems:
- Admin Guide: Documentation/admin-guide/index.rst
- Kernel Parameters: Documentation/admin-guide/kernel-parameters.rst
- Sysctl Tuning: Documentation/admin-guide/sysctl/index.rst
- Tracing/Debugging: Documentation/trace/index.rst
- Performance Security: Documentation/admin-guide/perf-security.rst
- Hardware Monitoring: Documentation/hwmon/index.rst
Maintainer
Lead kernel subsystems and manage contributions:
- Maintainer Handbook: Documentation/maintainer/index.rst
- Pull Requests: Documentation/maintainer/pull-requests.rst
- Managing Patches: Documentation/maintainer/modifying-patches.rst
- Rebasing and Merging: Documentation/maintainer/rebasing-and-merging.rst
- Development Process: Documentation/process/maintainer-handbooks.rst
- Maintainer Entry Profile: Documentation/maintainer/maintainer-entry-profile.rst
- Git Configuration: Documentation/maintainer/configure-git.rst
Hardware Vendor
Write drivers and support new hardware:
- Driver API Guide: Documentation/driver-api/index.rst
- Driver Model: Documentation/driver-api/driver-model/driver.rst
- Device Drivers: Documentation/driver-api/infrastructure.rst
- Bus Types: Documentation/driver-api/driver-model/bus.rst
- Device Tree Bindings: Documentation/devicetree/bindings/
- Power Management: Documentation/driver-api/pm/index.rst
- DMA API: Documentation/core-api/dma-api.rst
Distribution Maintainer
Package and distribute the kernel:
- Stable Kernel Rules: Documentation/process/stable-kernel-rules.rst
- ABI Documentation: Documentation/ABI/README
- Kernel Configuration: Documentation/kbuild/kconfig.rst
- Module Signing: Documentation/admin-guide/module-signing.rst
- Kernel Parameters: Documentation/admin-guide/kernel-parameters.rst
- Tainted Kernels: Documentation/admin-guide/tainted-kernels.rst
Communication and Support
- Mailing Lists: https://lore.kernel.org/
- IRC: #kernelnewbies on irc.oftc.net
- Bugzilla: https://bugzilla.kernel.org/
- MAINTAINERS file: Lists subsystem maintainers and mailing lists
- Email Clients: Documentation/process/email-clients.rst
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 -- this is a read-only mirror of the official repository at https://code.illumos.org/plugins/gitiles/illumos-gate
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