當前位置:首頁 » 操作系統 » linuxlist

linuxlist

發布時間: 2023-02-11 09:45:50

1. linux內核源碼解析-list.h

開頭就說明了這里的 list.h 文件來自 Linux Kernel ( */include/linux/list.h ),只是去除了列表項的硬體預載入部分。

進行宏替換後就是

Note: 沒搞懂這里為什麼加個 osn 前綴,原本是 list_add ,現在是 osn_list_add 。

可以看到就是個簡單的鏈表節點刪除過程,同時把刪除節點的前後指針設為無法訪問

刪除節點後初始化,前後指針都指向自己

從A鏈表刪除後頭插法插入B鏈表

從A鏈表刪除後尾插法插入B鏈表

先對 list 判空,非空就把 list 鏈表除頭節點外裁剪到 head 頭節點在的鏈表中。函數不安全, list 節點可以繼續訪問其他節點。

多了一步 list 重新初始化的過程。

(unsigned long)(&((type *)0)->member))) 將0x0地址強制轉換為 type * 類型,然後取 type 中的成員 member 地址,因為起始地址為0,得到的 member 的地址就直接是該成員相對於 type 對象的偏移地址了。
所以該語句的功能是:得到 type 類型對象中 member 成員的地址偏移量。
先將 ptr 強制轉換為 char * 類型(因為 char * 類型進行加減的話,加減量為 sizeof(char)*offset , char 佔一個位元組空間,這樣指針加減的步長就是1個位元組,實現加一減一。)
整句話的意思就是:得到指向 type 的指針,已知成員的地址,然後減去這個成員相對於整個結構對象的地址偏移量,得到這個數據對象的地址。

就是從前往後,從後往前的區別

Note: 從head節點開始(不包括head節點!)遍歷它的每一個節點!它用n先將下一個要遍歷的節點保存起來,防止刪除本節點後,無法找到下一個節點,而出現錯誤!

已知指向某個結構體的指針pos,以及指向它中member成員的指針head,從下一個結構體開始向後遍歷這個結構體鏈

Note: 同理,先保存下一個要遍歷的節點!從head下一個節點向後遍歷鏈表。

list.h使用說明
linux內核list.h分析(一)
linux內核list.h分析(二)
【Linux內核數據結構】最為經典的鏈表list

2. Linux系統中查看所有文件的命令是什麼

Linux中哪個命令可以查看所有文件?在Linux中有很多命令,但在日常工作中最最常用的並不多,而ls命令就是其中之一。ls命令是Linux中十分常見的一個命令,因為初學Linux的時候,最先接觸的就是ls命令,其主要功能是顯示當前目錄下的內容。

Linux系統中查看所有文件命令為ls。

Linux ls,英文全拼:list files,用於顯示指定工作目錄下的內容,列出目前工作目錄所含的文件及子目錄。

語法

ls [-alrtAFR] [name...]

參數

-a:顯示所有文件及目錄,.開頭的隱藏文件也會列出

-l:除文件名稱外,亦將文件型態、許可權、擁有者、文件大小等資訊詳細列出

-r:將文件以相反次序顯示,原定依英文字母次序

-t:將文件依建立時間之先後次序列出

-A:同-a,但不列出.(目前目錄)及..(父目錄)

-F:在列出的文件名稱後加一符號;例如可執行檔則加*,目錄則加/

-R:若目錄下有文件,則以下的文件亦皆依序列出

…………

3. linux怎樣引入list.h

不是標准代碼

可以自己寫一個

或者試試用內核代碼的list.h

看起來介面差不多

struct list_head {
struct list_head *next, *prev;};


#define LIST_HEAD_INIT(name) { &(name), &(name) }

#define LIST_HEAD(name)

struct list_head name = LIST_HEAD_INIT(name)

網頁鏈接

4. 如何在linux c 實現list-C/C++

C語言沒有類的概念。C++有現成的List類, #include<list>即可。
如果要自己實現可以參考C++數據結構的書籍,是最基本的練習。
這里實現一個簡單的常式,請參考:
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string.h>
using namespace std;
#include<stdio.h>
#include<string>

#include "math.h"

template<class T> class List{
public:
List() //構造函數
{
pFirst = NULL;
}

void Add(T& t) //在Link表頭添加新結點
{
if(pFirst == NULL)
{
pFirst = new Node;
*(pFirst->pT) = t;
}
else
{
Node* pNewNode = new Node;
*(pNewNode->pT) = t;
pNewNode->pNext = pFirst;
pFirst = pNewNode;
}
}

void Remove(T& t) //在Link中刪除含有特定值的元素
{
Node* pNode = pFirst;
if(*(pNode->pT) == t)
{
pFirst = pFirst->pNext;
delete pNode;
return;
}
while(pNode != NULL)
{
Node* pNextNode = pNode->pNext;
if(pNextNode!=NULL)
{
if(*(pNextNode->pT) == t)
{
pNode->pNext = pNextNode->pNext;
delete pNextNode;
return;
}
}
else
return;//沒有相同的

pNode = pNode->pNext;
}
}
T* Find(T& t) //查找含有特定值的結點
{
Node* pNode = pFirst;
while(pNode != NULL)
{
if(*(pNode->pT) == t)
{
return pNode->pT;
}
pNode = pNode->pNext;
}
return NULL;
}
void PrintList() // 列印輸出整個鏈表
{
if(pFirst == NULL)
{
cout<<"列表為空列表!"<<endl;
return;
}
Node* pNode = pFirst;
while(pNode != NULL)
{
cout<<*(pNode->pT)<<endl;
pNode = pNode->pNext;
}
}
~List()
{
Node* pNode = pFirst;
while(pNode != NULL)
{
Node* pNextNode = pNode->pNext;
delete pNode;
pNode = pNextNode;
}
}
protected:
struct Node{
Node* pNext;
T* pT;

Node()
{
pNext = NULL;
pT = new T;
}
~Node()
{
delete pT;
}
};
Node *pFirst; //鏈首結點指針
};

class Student
{
public:
char id[20]; //學號
char name[20]; //姓名
int age; //年齡
Student()
{
}
~Student()
{
}
Student(const char* pid, const char* pname, int _age)
{
strcpy(id, pid);
strcpy(name, pname);
age = _age;
}
bool operator==(const Student& stu)
{
return strcmp(id, stu.id) == 0 && strcmp(id, stu.id) == 0 && age==stu.age;
}
Student& operator=(const Student& stu)
{
strcpy(id, stu.id);
strcpy(name, stu.name);
age = stu.age;
}
friend ostream& operator<< (ostream &out,const Student& stu);
};
ostream & operator<< (ostream &out,const Student& stu)
{
out<<"id:"<<stu.id<<"\tname:"<<stu.name<<"\tage:"<<stu.age<<endl;
}

int main()
{
List<Student> stuList;
cout<<"添加學生前:"<<endl;
stuList.PrintList();

Student stu1("1", "張三", 18);
Student stu2("2", "李四", 18);
Student stu3("3", "王五", 18);
Student stu4("4", "至尊寶", 18);
Student stu5("5", "豬八戒", 18);
Student stu6("6", "唐僧", 18);
Student stu7("7", "沙和尚", 18);
Student stu8("8", "觀音", 18);
stuList.Add(stu1);
stuList.Add(stu2);
stuList.Add(stu3);
stuList.Add(stu4);
stuList.Add(stu5);
stuList.Add(stu6);
stuList.Add(stu7);
stuList.Add(stu8);
cout<<"添加學生後:"<<endl;
stuList.PrintList();

Student stu11("1", "張三", 18);
Student* pStu = stuList.Find(stu11);
cout<<"查找到的同學是:"<<*pStu;

stuList.Remove(stu11);
cout<<"\n\n刪除第一個後:"<<endl;
stuList.PrintList();

return 0;
}

5. 如何在linux c 實現list

C語言沒有類的概念。C++有現成的List類, #include<list>即可。
如果要自己實現可以參考C++數據結構的書籍,是最基本的練習。
這里實現一個簡單的常式,請參考:
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string.h>
using namespace std;
#include<stdio.h>
#include<string>

#include "math.h"

template<class T> class List{
public:
List() //構造函數
{
pFirst = NULL;
}

void Add(T& t) //在Link表頭添加新結點
{
if(pFirst == NULL)
{
pFirst = new Node;
*(pFirst->pT) = t;
}
else
{
Node* pNewNode = new Node;
*(pNewNode->pT) = t;
pNewNode->pNext = pFirst;
pFirst = pNewNode;
}
}

void Remove(T& t) //在Link中刪除含有特定值的元素
{
Node* pNode = pFirst;
if(*(pNode->pT) == t)
{
pFirst = pFirst->pNext;
delete pNode;
return;
}
while(pNode != NULL)
{
Node* pNextNode = pNode->pNext;
if(pNextNode!=NULL)
{
if(*(pNextNode->pT) == t)
{
pNode->pNext = pNextNode->pNext;
delete pNextNode;
return;
}
}
else
return;//沒有相同的

pNode = pNode->pNext;
}
}
T* Find(T& t) //查找含有特定值的結點
{
Node* pNode = pFirst;
while(pNode != NULL)
{
if(*(pNode->pT) == t)
{
return pNode->pT;
}
pNode = pNode->pNext;
}
return NULL;
}
void PrintList() // 列印輸出整個鏈表
{
if(pFirst == NULL)
{
cout<<"列表為空列表!"<<endl;
return;
}
Node* pNode = pFirst;
while(pNode != NULL)
{
cout<<*(pNode->pT)<<endl;
pNode = pNode->pNext;
}
}
~List()
{
Node* pNode = pFirst;
while(pNode != NULL)
{
Node* pNextNode = pNode->pNext;
delete pNode;
pNode = pNextNode;
}
}
protected:
struct Node{
Node* pNext;
T* pT;

Node()
{
pNext = NULL;
pT = new T;
}
~Node()
{
delete pT;
}
};
Node *pFirst; //鏈首結點指針
};

class Student
{
public:
char id[20]; //學號
char name[20]; //姓名
int age; //年齡
Student()
{
}
~Student()
{
}
Student(const char* pid, const char* pname, int _age)
{
strcpy(id, pid);
strcpy(name, pname);
age = _age;
}
bool operator==(const Student& stu)
{
return strcmp(id, stu.id) == 0 && strcmp(id, stu.id) == 0 && age==stu.age;
}
Student& operator=(const Student& stu)
{
strcpy(id, stu.id);
strcpy(name, stu.name);
age = stu.age;
}
friend ostream& operator<< (ostream &out,const Student& stu);
};
ostream & operator<< (ostream &out,const Student& stu)
{
out<<"id:"<<stu.id<<"\tname:"<<stu.name<<"\tage:"<<stu.age<<endl;
}

int main()
{
List<Student> stuList;
cout<<"添加學生前:"<<endl;
stuList.PrintList();

Student stu1("1", "張三", 18);
Student stu2("2", "李四", 18);
Student stu3("3", "王五", 18);
Student stu4("4", "至尊寶", 18);
Student stu5("5", "豬八戒", 18);
Student stu6("6", "唐僧", 18);
Student stu7("7", "沙和尚", 18);
Student stu8("8", "觀音", 18);
stuList.Add(stu1);
stuList.Add(stu2);
stuList.Add(stu3);
stuList.Add(stu4);
stuList.Add(stu5);
stuList.Add(stu6);
stuList.Add(stu7);
stuList.Add(stu8);
cout<<"添加學生後:"<<endl;
stuList.PrintList();
Student stu11("1", "張三", 18);
Student* pStu = stuList.Find(stu11);
cout<<"查找到的同學是:"<<*pStu;

stuList.Remove(stu11);
cout<<"\n\n刪除第一個後:"<<endl;
stuList.PrintList();

return 0;
}

6. Linux kernel中的list怎麼使用

為什麼一定要別人說的才是權威呢?
你可以再LKM編程中自己驗證一下,構造幾個包含struct list_head的結構體元素,初始化一個頭,然後依次調用list_add_tail入鏈表,然後在list_for_each_entry列印出來看,你就可以知道它到底是怎麼插的了!
多動手,你查遍所有資料還不如3分鍾的幾行代碼

7. linux中&>list是什麼意思

&>list前面有其他命令嗎?如果沒有,我不知道這是什麼意思。如果有,那麼這是將前面命令的正確輸出和報錯輸出都寫入到名為list文件中去。也可以寫成2&>list或者>list
2>list。

熱點內容
6s和安卓8哪個值得入手 發布:2025-07-23 23:03:31 瀏覽:766
巧妙運演算法 發布:2025-07-23 23:02:02 瀏覽:140
sql解析json 發布:2025-07-23 22:48:16 瀏覽:905
戰神解壓密碼 發布:2025-07-23 22:29:07 瀏覽:224
如何刷機安卓系統手機 發布:2025-07-23 22:28:56 瀏覽:739
麥咭編程下載 發布:2025-07-23 22:20:04 瀏覽:36
javadraw 發布:2025-07-23 22:19:59 瀏覽:629
忘記密碼去哪裡找回 發布:2025-07-23 22:19:06 瀏覽:748
php培訓技術 發布:2025-07-23 22:18:21 瀏覽:608
兒童速演算法 發布:2025-07-23 22:09:37 瀏覽:637