Exploring /proc

本文介绍了Linux的/proc伪文件系统,它驻留在虚拟内存中,跟踪系统进程和状态。通过查看/proc文件系统参数,可了解内核和进程状态,如dmesg、ps和top命令信息就源于此。还介绍了/proc/sys目录可实时修改内核参数,以及/proc目录内容和各子目录含义。
Exploring /proc
By Trevor Warren <trevorwarren@yahoo.com>
Posted: ( 2000-12-12 10:03:00 EST by )
The Proc psuedo file system is a real time, memory resident file system
that tracks the processes running on your machine and the state of your
system. Read on to learn how to get the most out of the /proc file system.

The most striking factor about the /proc file system is the fact that the
file system doesn't exist on any particular media. The /proc File System
is a pseudo file system residing in the virtual memory and
maintains highly dynamic data on the state of your operating system. Most
of the information in the /proc file system is updated to match the
current state of the operating system. The contents of the /proc file
system can be read by anyone who has the requisite permissions. However,
certain parts of the /proc file system can be read only by the owner of
the process and of course root. The contents of the /proc filesystem are
used by many utilities which grab the data from the particular /proc
directory and display it.
Under Linux, we have utilities like lscpi, scanpci and pnpdump which help
us detect the various PCI, ISA hardware chipsets and help us make the best
choices as far as the io, dma and irq values are concerned. Similarly by
looking at the values of the various parameters in the /proc file system,
one can determine a lot about the current state of the kernel and the
processes under way. For example, we have the dmesg command.
bash# dmesg
Dmesg helps us determine the devices that have been detected and
initialized by the Linux kernel. We have utilities like "ps" and "top"
which give an accurate snapshot about the status of the processes running
on the machine and a list of awake and sleeping processes currently
running on the machine. Have you ever wondered where exactly the
information dished out to you by the "ps" and the "top" process comes
from? The information for these processes come from the /proc file system
which is updated on the fly as changes take place in the processes.
Lets take a look at a snapshot of the directory listing of the root (/)
directory of a Linux machine.
drwxr-xr-x 14 root root 291 Oct 25 18:47 opt
dr-xr-xr-x 86 root root 0 Nov 30 2000 proc <--
drwx--x--x 16 root root 841 Nov 20 00:10 root
drwxr-xr-x 5 root root 4627 Oct 15 11:42 sbin
Since the /proc file system is a virtual file system and resides in
memory, a new /proc file system is created every time your Linux machine
reboots. Take a look at the snapshot of the root directory shown above.
The size of the proc directory is 0 and the last time of modification is
the current date.
Using the /proc/sys file system to parse kernel parameters.
Another very important part of the /proc file system is the /proc/sys
directory. Making changes in this directory enables you to make real time
changes to certain kernel parameters. One fine example that can illustrate
this is as follows.
/proc/sys/net/ipv4/ip_forward

The above file ip_forward has a default value of "0" which you can see
when you cat the contents of this file. This means that IP forwarding by
this machine isn't allowed by the kernel. But this configuration can be
changed in real time by just changing the value stored in this file from
"0" to "1". Thus we have enabled IP forwarding on our Linux machine.

Contents of the /proc File System
The output of the directory listing of the /proc directory is as follows.
The actual listing was really lengthy. What's given below is a much
shorter version.

1 114 1210 1211 1212 1227 133 137 148 160 161 163 167 168 169
170 171 172 173 174 186 190 193 194 195 203 206 207 208 209
210 211 220 221 222 223 224 225 226 227 229 230 234 246 253 279
296 3 4 5 500 501 6 667 668 669 683 684 685 7 711 712 713 737 763
764 765 766 773 774 775 782 79 88 92 asound bus cmdline config.gz
cpuinfo devices dma fb filesystems fs ide interrupts ioports
kcore kcore_elf kmsg ksyms loadavg locks lvm mdstat meminfo
memstat misc modules mounts net partitions pci rtc scsi self
slabinfo stat swaps sys tty uptime version
Every number and word that you see in the above snapshot are the contents of
the /proc directory. Lets learn a little more about the contents of the
directories with the numerical naming scheme.
The numerical named directories
1 114 1210 1211 1212 1227 133 137 148 160 161 163 167 168 169
170 171 172 173 174 186 190 193 194 195 203 206 207 208 209
210 211 220 221 222 223 224 225 226 227 229 230 234 246 253 279
296 3 4 5 500 501 6 667 668 669 683 684 685 7 711 712 713 737 763
764 765 766 773 774 775 782 79 88 92
The various directories that you see out here are the processes that were
running on our machine at the instant we took a snapshot of the /proc
file system. Let's look at the contents of one of these directories.
freeos:~ # cd /proc
freeos:/proc # ls -la 114
total 0
dr-xr-xr-x 3 named named 0 Nov 30 12:20 .
dr-xr-xr-x 89 root root 0 Nov 30 2000 ..
-r--r--r-- 1 root root 0 Nov 30 12:20 cmdline
lrwx------ 1 root root 0 Nov 30 12:20 cwd -> /var/named
-r-------- 1 root root 0 Nov 30 12:20 environ
lrwx------ 1 root root 0 Nov 30 12:20 exe -> /usr/sbin/named
dr-x------ 2 root root 0 Nov 30 12:20 fd
pr--r--r-- 1 root root 0 Nov 30 12:20 maps
-rw------- 1 root root 0 Nov 30 12:20 mem
lrwx------ 1 root root 0 Nov 30 12:20 root -> /
-r--r--r-- 1 root root 0 Nov 30 12:20 stat
-r--r--r-- 1 root root 0 Nov 30 12:20 statm
-r--r--r-- 1 root root 0 Nov 30 12:20 status
Before executing this command you need to log in as root because the
various processes running on the system may be owned by various other
users. As usual you have access only to the processes that you have
started. After having logged in as root just execute the above command for
any of the directories and compare the output to what is listed above.
Did you notice any similarity in the output you got and the one listed
above? Yes, the contents of all the directories are the same irrespective
of the directory you choose to view as these directories contain the
various parameters and the status of the process whose PID is the name of
the current directory that you are in. The values of the various
parameters and status information would of course vary from process to
process.
Look at the first line of the output as viewed above.
-r--r--r-- 1 root root 0 Nov30 12:20 cmdline
"cmdline", this file contains the whole command line used to invoke the
process. The contents of this file are the command line arguments with all
the parameters that one has passed to start the particular process. All
the information contained in the file is without any formatting and any
space between the command line arguments and various arguments.
lrwx------ 1 root root 0 Nov 30 12:20 cwd -> /var/named
"cwd", as is visible from above this is a symbolic link to the current
working directory of that particular process.
-r-------- 1 root root 0 Nov 30 12:20 environ
"environ" contains all the environment variables defined for this
particular process in the form VARIABLE=value. As with cmdline, all the
information contained in the file is without any formatting or space
between the command line arguments and various arguments.
lrwx------ 1 root root 0 Nov 30 12:20 exe -> /usr/sbin/named
"exe", this is a symbolic link to the executable file that the current
process is linked to.
dr-x------ 2 root root 0 Nov 30 12:20 fd
"fd", this directory contains the list file descriptors as opened by the
particular process.
pr--r--r-- 1 root root 0 Nov 30 12:20 maps
"maps", when you print the contents of this named pipe, you can see the
parts of the process' address space which are currently mapped to a file.
The fields, from left to right, are: the address space associated to this
mapping, the permissions associated to this mapping, the offset from the
beginning of the file where the mapping starts, the device on which the
mapped file is located, the inode number of the file and finally, the name
of the file itself.
lrwx------ 1 root root 0 Nov 30 12:20 root -> /
"root", this is a symbolic link pointing to the directory which is the
root file system for the particular process.
-r--r--r-- 1 root root 0 Nov 30 12:20 status
"status", this file gives information regarding the name of the process,
its current status, i.e sleeping or awake, its PID, its UID, its PPID and
a lot of other general information. This information can be viewed in a
simpler and structured manner by using tools like, "ps" and "top".
Generic information about the various /proc/* directories
This information has been sourced from the LASG, Chapter 3
The /proc filesystem
/proc/cpuinfo
Information about the processor, such as its type, make, model, and
performance.
/proc/devices
List of device drivers configured into the currently running kernel.
/proc/dma
Shows which DMA channels are being used at the moment.
/proc/filesystems
Filesystems configured into the kernel.
/proc/interrupts
Shows which interrupts are in use, and how many of each there have been.
/proc/ioports
Which I/O ports are in use at the moment.
Hope this article has been informative guide to the /proc File system.
Demo: Exploring Data with SAS Procedures In this demonstration, we use the PRINT, MEANS, UNIVARIATE, and FREQ procedures to explore and validate our data. Reminder: If you restarted your SAS session,you must recreate the PG1 library so you can access your practice files. In SAS Studio, open and submit the libname.sas program in the EPG1V2 folder. In Enterprise Guide, run the Autoexec process flow. Note: If you did not create the libname.sas program, complete the Activity: Create a Library for This Course (REQUIRED) in Lesson 2. Open p103d01.sas from the demos folder and locate the Demo section of the program. Complete the PROC PRINT statement to list the data in pg1.storm_summary. Use the DATA= option to specify the table name. Use the OBS= option to print only the first 10 observations. Highlight the step and run the selected code. Open code or syntax in a separate window. proc print data=pg1.storm_summary (obs=10); run; Review the output. The first 10 rows are displayed and all columns are included. Let's select the columns to include, and add a comment to document the program. Add a VAR statement to include only the following columns: Season, Name, Basin, MaxWindMPH, MinPressure, StartDate, and EndDate. Enterprise Guide: To easily add column names, use the autocomplete prompts to view and select columns. You can either double-click on a column to add it in the program, or start to type the column name and press the spacebar when the correct column is highlighted. SAS Studio: To easily add column names, place your cursor after the keyword VAR. Use the Library section of the navigation pane to find the pg1 library. Expand the storm_summary table to see a list of column names. Hold down the Ctrl key and select the columns in the order in which you want them to appear in the statement. Drag the selected columns to the VAR statement. Add the comment, list first 10 rows, before the PROC PRINT statement. Highlight the step and run the selected code. Open code or syntax in a separate window. /*list first 10 rows*/ proc print data=pg1.storm_summary(obs=10); var Season Name Basin MaxWindMPH MinPressure StartDate EndDate; run; Review the output. The output contains10 rows, but we've limited the columns and changed their order in the report. Remember we're using these procedures to validate our data. As we look at the values we notice that there are missing values for Name, and that Basin includes both lowercase and uppercase NA. There are also some missing values for MaxWindMPH and MinPressure. And that's just in the first 10 rows. Let's use other procedures to validate our data. Next we'll use PROC MEANS to compute summary statistics. Copy the PROC PRINT step, paste it at the end of the program and change PRINT to MEANS Remove the OBS= data set option to analyze all observations. Modify the VAR statement to include only MaxWindMPH and MinPressure. The columns on the VAR statement must be numeric. Add calculate summary statistics as a comment before the PROC MEANS statement. Highlight the step and run the selected code. Open code or syntax in a separate window. /*calculate summary statistics*/ proc means data=pg1.storm_summary; var MaxWindMPH MinPressure; run; Review the output. The report includes basic summary statistics for these two numeric columns. The frequency count, N, has different values for each column. This indicates that there are quite a few missing values for MinPressure compared to MaxWindMPH. You might want to look at the Minimum and Maximum to see if those ranges appear valid. Six is a pretty small value for MaxWindMPH. We might want to investigate further to see if this is a valid value. And negative 9,999 is definitely not valid for MinPressure. Next we'll use PROC UNIVARIATE to compute summary statistics including the 5 extreme low and high values. Copy the PROC MEANS step, paste it at the end of the program, and change MEANS to UNIVARIATE. Add examine extreme values as a comment before the PROC UNIVARIATE statement. Highlight the step and run the selected code. Open code or syntax in a separate window. /*examine extreme values*/ proc univariate data=pg1.storm_summary; var MaxWindMPH MinPressure; run; Review the output. Scroll down to the Extreme Observations table. It includes the observation number and the value for the low and high MaxWindMPH values. We might be interested later on in learning which storm had a maximum wind speed of 213 miles per hour. Scroll down to the Extreme Observations report for MinPressure. There are only two rows where the value for MinPressure was negative 9,999. That gives us a little more insight as to what we're dealing with in our data. Let's use PROC FREQ to generate one-way frequency reports. Copy the PROC UNIVARIATE step and paste it at the end of the program. Copy the PROC UNIVARIATE step, paste it at the end of the program, and change UNIVARIATE to FREQ. Change the VAR statement to a TABLES statement to produce frequency tables for Basin, Type, and Season. Add list unique values and frequencies as a comment before the PROC FREQ statement. Highlight the step and run the selected code. Open code or syntax in a separate window. /*list unique values and frequencies*/ proc freq data=pg1.storm_summary; tables Basin Type Season; run; Review the output. Recall that our PROC PRINT output showed that there were some lower case values for Basin. The Frequency table for Basin indicates that 16 rows have a lowercase na value. We'll need to correct that later on. The Type frequency table shows no case inconsistencies or incorrect values. The frequency table for Season shows how many storms there were per season. We can identify those seasons that had the most storms, such as 2005 with 102. These procedures give us insight to our data. They help us to learn about the data values and what we may need to fix as we prepare our data. They also help us think about questions we may want to answer as we analyze our data further.
09-06
内容概要:本文介绍了一个基于Matlab的综合能源系统优化调度仿真资源,重点实现了含光热电站、有机朗肯循环(ORC)和电含光热电站、有机有机朗肯循环、P2G的综合能源优化调度(Matlab代码实现)转气(P2G)技术的冷、热、电多能互补系统的优化调度模型。该模型充分考虑多种能源形式的协同转换与利用,通过Matlab代码构建系统架构、设定约束条件并求解优化目标,旨在提升综合能源系统的运行效率与经济性,同时兼顾灵活性供需不确定性下的储能优化配置问题。文中还提到了相关仿真技术支持,如YALMIP工具包的应用,适用于复杂能源系统的建模与求解。; 适合人群:具备一定Matlab编程基础和能源系统背景知识的科研人员、研究生及工程技术人员,尤其适合从事综合能源系统、可再生能源利用、电力系统优化等方向的研究者。; 使用场景及目标:①研究含光热、ORC和P2G的多能系统协调调度机制;②开展考虑不确定性的储能优化配置与经济调度仿真;③学习Matlab在能源系统优化中的建模与求解方法,复现高水平论文(如EI期刊)中的算法案例。; 阅读建议:建议读者结合文档提供的网盘资源,下载完整代码和案例文件,按照目录顺序逐步学习,重点关注模型构建逻辑、约束设置与求解器调用方式,并通过修改参数进行仿真实验,加深对综合能源系统优化调度的理解。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值