task_struct解析

task_struct是Linux內核的一種數據結構,它用task_struct結構體來描述進程的信息。下面來剖析一下進程中保存的主要的信息有哪些?

struct task_struct {//進程的運行時狀態volatile long state;    /* -1 unrunnable, 0 runnable, >0 stopped */void *stack;   atomic_t usage;//進程當前的狀態/*0x00000002表示進程正在被創建;0x00000004表示進程正準備退出;0x00000040 表示此進程被fork出,但是并沒有執行exec;0x00000400表示此進程由于其他進程發送相關信號而被殺死 。*/unsigned int flags;     /* per process flags, defined below */unsigned int ptrace;int on_rq;//表示此進程的運行優先級,prio表示動態優先級,根據static_prio和交互性獎罰算出,static_prio是進程的靜態優先級,在進程創建時確定,范圍從-20到19,越小優先級越高。int prio, static_prio, normal_prio;//進程的運行優先級unsigned int rt_priority;//list_head結構體struct list_head tasks;//mm_struct結構體,描述了進程內存的相關情況struct mm_struct *mm, *active_mm;/* per-thread vma caching */u32 vmacache_seqnum;struct vm_area_struct *vmacache[VMACACHE_SIZE];/* task state *///進程的狀態參數int exit_state;int exit_code, exit_signal;//父進程退出后信號被發送int pdeath_signal;  /*  The signal sent when the parent dies  */ /* scheduler bits, serialized by scheduler locks */unsigned sched_reset_on_fork:1;unsigned sched_contributes_to_load:1;unsigned sched_migrated:1;unsigned sched_remote_wakeup:1;unsigned :0; /* force alignment to the next boundary *//* unserialized, strictly 'current' */unsigned in_execve:1; /* bit to tell LSMs we're in execve */unsigned in_iowait:1;struct restart_block restart_block;//進程號pid_t pid;//進程組號pid_t tgid;//進程的親身父親struct task_struct __rcu *real_parent; /* real parent process *///進程的現在的父親,可能為繼父struct task_struct __rcu *parent; /* recipient of SIGCHLD, wait4() reports *///進程的孩子鏈表struct list_head children;      /* list of my children *///進程兄弟的鏈表struct list_head sibling;       /* linkage in my parent's children list *///主線程的進程描述符struct task_struct *group_leader;       /* threadgroup leader *//* PID/PID hash table linkage. */struct pid_link pids[PIDTYPE_MAX];//該進程的所有線程鏈表struct list_head thread_group;struct list_head thread_node;//該進程使用cpu時間的信息,utime是在用戶態下執行的時間,stime是在內核態下執行的時間。cputime_t utime, stime;cputime_t gtime;struct prev_cputime prev_cputime;//啟動時間,,只是時間基準不一樣u64 start_time;         /* monotonic time in nsec */u64 real_start_time;    /* boot based time in nsec */struct task_cputime cputime_expires;//list_head的CPU時間struct list_head cpu_timers[3];//保存進程名字的數組,一般數組大小為15位char comm[TASK_COMM_LEN];/* file system info *///文件系統信息struct nameidata *nameidata;/* 文件系統信息計數*/int link_count, total_link_count;/* filesystem information *///文件系統相關信息結構體struct fs_struct *fs;/* open file information *///打開文件信息的結構體struct files_struct *files;/* namespaces */struct nsproxy *nsproxy;/* signal handlers *///信號相關信息的句柄struct signal_struct *signal;struct sighand_struct *sighand;struct callback_head *task_works;struct audit_context *audit_context;struct seccomp seccomp;/* Thread group tracking */u32 parent_exec_id;u32 self_exec_id;/* journalling filesystem info */void *journal_info;/* VM state */struct reclaim_state *reclaim_state;struct backing_dev_info *backing_dev_info;struct io_context *io_context;unsigned long ptrace_message;siginfo_t *last_siginfo; /* For ptrace use.  *//** time slack values; these are used to round up poll() and* select() etc timeout values. These are in nanoseconds.*///松弛時間值,用來記錄select和poll的超時時間,單位為nsu64 timer_slack_ns;u64 default_timer_slack_ns;/* CPU-specific state of this task *///該進程在特定CPU下的狀態struct thread_struct thread;};

今天我們只是簡單的了解了一下進程的信息,往后會再詳細講解進程。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/382737.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/382737.shtml
英文地址,請注明出處:http://en.pswp.cn/news/382737.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

ubuntu上有個小項目 ,需要調用xx.sh腳本, 出現無法識別 某些環境變量的解決辦法,僅供參考

項目是用python 調用 同事寫好的 xx.sh腳本, 在手動調用的時候 發現能正常調用, 當用python代碼的時候, 就不行了, 通過日志發現, python調用的時候 不識別 ADNROID_NDK這個環境變量, 在python中 我是通過&…

關于sudo

之前,我們使用sudo的時候,是因為其用戶本身具有root權限,所以可以sudo后執行相關操作,但是對于普通用戶來說,它是既不具有sudo權限,又不在sudo用戶組中,那么我們來研究一下如何將新創建的用戶添…

在使用 python 封裝的進程池 from concurrent.futures import ProcessPoolExecutor 遇到的問題

在ubuntu中,用的是python3.5 executeprebuildpath ExecutePrebuild()processpool ProcessPoolExecutor(1)processpool.submit(executeprebuildpath.run).add_done_callback(self.precallback)processpool.shutdown(waitFalse)self.runsign Trueself.runningprebu…

對pthread_create未定義的引用

pthread庫不是Linux系統默認的庫,連接時需要使用庫libpthread.a,在編譯中要加-lpthread [koulocalhost practive]$ gcc creat.c /tmp/ccPULtaF.o:在函數‘main’中: creat.c:(.text0x58):對‘pthread_create’未定義的引用 coll…

Bash入門

Bash簡介: Bash(GNU Bourne-Again Shell)是一個為GNU計劃編寫的Unix shell,它是許多Linux平臺默認使用的shell。 shell是一個命令解釋器,是介于操作系統內核與用戶之間的一個絕緣層。準確地說,它也是能力…

ubuntu 設置分辨率 親測可用 轉載的

網上試了很多方法, 這家管用 https://blog.csdn.net/qq_35661436/article/details/72802040

線程之售票系統pthread_mutex,_lock,_unlock

先看一下這篇文章 https://blog.csdn.net/csdn_kou/article/details/81148268 四個人同時買票票,引出線程 #include "head.h" int ticket 100; void * route(void *arg) {char *id (char *)arg;while(1){if(ticket>0){usleep(1000);printf("…

Bash基本語法

1. 變量賦值 a375 hello$a 這里需要注意的是,等號兩邊不能有空格 還有一個例子是這樣的 例1: 結果為: 關于上述,主要有如下幾點: $hello和${hello}是一樣的,在bash中如果遇到空格,tab鍵時&a…

windows下 , py運用了 進程池, 將py打包成exe,出現錯誤的 解決思路之一

在windows上,用pycharm開發了一個小項目, 用到了from concurrent.futures import ProcessPoolExecutor 本來在pycharm里面,運行的好好地, 可是打包成exe的時候, 發現 當程序運行到 進程池執行任務的時候,會創建一個新的界面, 猜測應該是創建了一個新的進程, 百度后,發現在 程序…

關于fd和fp(fd:file descirptor fp:file pointor)

通常,我們在輸入數據或輸出數據的設備為鍵盤或者顯示器。當然,我們比較熟悉的輸入輸出,可能就是對于文件的操作,還有直接從終端輸出,顯示到顯示器上。在C語言中,我們使用fopen,fclose,fread,fwrite對文件進…

粗談pragma once與 #ifndef的區別

#ifnde不受編譯器的任何限制; #pragma once不受一些較老的編譯器支持,兼容性不夠好

在mac os10.13系統下 ,將py文件打包成可執行程序后, 里面的路徑出現的問題

本來 用命令行運行py文件, 代碼里面 獲取當前路徑的 語句 例如: os.getcwd() os.path.abspath(__file__) os.path.realpath(__file__)都可以獲取到當前文件的路徑, 但是打包成 可執行程序后, 統統不對了, 變成了 類似 /usr/xxx 的路徑 https://stackoverflow.com/questions/50…

[linux]wait詳解

wait:進程等待 主要有兩種等待方式:阻塞式等待和非阻塞式等待 阻塞式等待:如果子進程正在運行,父進程將會一直等待著子進程運行結束,并且自己什么事都不干 非阻塞式等待:如果子進程正在運行,…

centos 使vim支持+python和+python3

本文為了給ycm服務,不單獨存在。 查看是否支持python vim --version | grep python然后 下載vim8源碼: git clone https://github.com/vim/vim.git 1 進行編譯安裝,添加python3和python2.7的支持: 進入下載的vim的源碼文件夾中&#x…

ffmpeg的學習-00

命令行 大體樣式 ffmpeg [global_options] {[input_file_options] -i input_url} ... {[output_file_options] output_url} ...有道翻譯的 以后仔細回看 2.描述 ffmpeg是一個非常快的視頻和音頻轉換器,也可以從一個實時音頻/視頻源抓取。它還可以轉換之間的任意采樣…

[Linux]消息隊列

我們知道進程間通信的方法有多種,主要有管道,消息隊列,信號量,共享內存,socket等。之前介紹過管道,今天再介紹一個新的概念–消息隊列。 消息隊列:將一個進程到另一個進程之間發送數據塊的方式…

詳解centos7 YCM YouCompleteMe自動補全安裝,親測成功

文章經重新排版轉移至以下鏈接 https://blog.csdn.net/csdn_kou/article/details/84633663

python 異步與io

文檔地址: https://docs.python.org/zh-cn/3/library/asyncio.html 以后再記錄學習筆記 待續。。。

tornado 學習注意事項--00

設置url匹配的時候, (r/(.*), AMStaticFileHandler,dict(pathos.path.join(current_path, html), default_filenameindex.html))像這種語句要放到最后,因為放到前面的話, 后面的就無法匹配!