⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 node11.html

📁 Linux可卸载模块编程
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!--Converted with LaTeX2HTML 98.1 release (February 19th, 1998)
originally by Nikos Drakos (nikos@cbl.leeds.ac.uk), CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>Hello, world</TITLE>
<META NAME="description" CONTENT="Hello, world">
<META NAME="keywords" CONTENT="mpg">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="mpg.css">
<LINK REL="next" HREF="node14.html">
<LINK REL="previous" HREF="node2.html">
<LINK REL="up" HREF="mpg.html">
<LINK REL="next" HREF="node12.html">
</HEAD>
<BODY >
<!--Navigation Panel-->
<A NAME="tex2html516"
 HREF="node12.html">
<IMG WIDTH="37" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="next"
 SRC="next_motif.gif"></A> 
<A NAME="tex2html512"
 HREF="mpg.html">
<IMG WIDTH="26" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="up"
 SRC="up_motif.gif"></A> 
<A NAME="tex2html506"
 HREF="node10.html">
<IMG WIDTH="63" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="previous"
 SRC="previous_motif.gif"></A> 
<A NAME="tex2html514"
 HREF="node1.html">
<IMG WIDTH="65" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="contents"
 SRC="contents_motif.gif"></A> 
<A NAME="tex2html515"
 HREF="node34.html">
<IMG WIDTH="43" HEIGHT="24" ALIGN="BOTTOM" BORDER="0" ALT="index"
 SRC="index_motif.gif"></A> 
<BR>
<B> Next:</B> <A NAME="tex2html517"
 HREF="node12.html">Makefiles for Kernel Modules</A>
<B> Up:</B> <A NAME="tex2html513"
 HREF="mpg.html">Linux Kernel Module Programming</A>
<B> Previous:</B> <A NAME="tex2html507"
 HREF="node10.html">For version 1.1.0</A>
<BR>
<BR>
<!--End of Navigation Panel-->

<H1><A NAME="SECTION00300000000000000000">&#160;</A><A NAME="hello-world">&#160;</A>
<BR>
Hello, world
</H1>

<P>
When the first caveman programmer chiseled the first program on the walls
of the first cave computer, it was a program to paint the string `Hello,
world' in Antelope pictures. Roman programming textbooks began with the 
`Salut, Mundi' program. I don't know what happens to people who break with
this tradition, and I think it's safer not to find out.
<A NAME="109">&#160;</A>
<A NAME="110">&#160;</A>

<P>
A kernel module has to have at least two functions: <TT>init_module</TT> which 
is called when the module is inserted into the kernel, and 
<TT>cleanup_module</TT> which is called just before it is removed. 
Typically, <TT>init_module</TT> either registers
a handler for something with the kernel, or it replaces one of the kernel
function with its own code (usually code to do something and then call
the original function). The <TT>cleanup_module</TT> function is supposed to undo 
whatever <TT>init_module</TT> did, so the module can be unloaded safely.
<A NAME="116">&#160;</A>
<A NAME="117">&#160;</A>

<P>
ex
 
<FONT SIZE="+1"><B>hello.c</B></FONT> 
<A NAME="122">&#160;</A><A NAME="123">&#160;</A> 

<P>
<PRE>
 
/* hello.c 
 * Copyright (C) 1998 by Ori Pomerantz
 * 
 * "Hello, world" - the kernel module version. 
 */

/* The necessary header files */

/* Standard in kernel modules */
#include &lt;linux/kernel.h&gt;   /* We're doing kernel work */
#include &lt;linux/module.h&gt;   /* Specifically, a module */



/* Deal with CONFIG_MODVERSIONS */
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include &lt;linux/modversions.h&gt;
#endif        



/* Initialize the module */
int init_module()
{
  printk("Hello, world - this is the kernel speaking\n");

  /* If we return a non zero value, it means that 
   * init_module failed and the kernel module 
   * can't be loaded */
  return 0;
}


/* Cleanup - undid whatever init_module did */
void cleanup_module()
{
  printk("Short is the life of a kernel module\n");
}
</PRE>

<P>
<BR><HR>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS">&#160;</A>
<UL>
<LI><A NAME="tex2html518"
 HREF="node12.html">Makefiles for Kernel Modules</A>
<LI><A NAME="tex2html519"
 HREF="node13.html">Multiple File Kernel Modules</A>
</UL>
<!--End of Table of Child-Links-->
<BR><HR>
<ADDRESS>
<I></I>
<BR><I>1999-05-19</I>
</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -