A process contract is the formal definition of the relationship that
exists between a Process A and its monitoring rocess. In case process A
terminates abnormally, the monitoring process will be able to restart
it.
This is a small exercise that is using the contract subsystem and its associated commmands.
0. Get some information
# man contract
1. SMF and contracts
Check the state of the “syslog” service :
# svcs system-log
STATE STIME FMRI
online Dec_10 svc:/system/system-log:default
#
# pgrep -fl syslog
658 /usr/sbin/syslogd
# ps -o pid,comm,ctid | grep syslog
658 /usr/sbin/syslogd 35
# svcs -pv system-log
STATE NSTATE STIME CTID FMRI
online - Dec_10 35 svc:/system/system-log:default
Dec_10 658 syslogd
All
these commands show that the service is enabled ( syslogd is started
with pid 658 ) and is monitored by the contract subsystem using
ContractID 35.
Another command shows more information about the contract :
#ctstat -i 35
CTID ZONEID TYPE STATE HOLDER EVENTS QTIME NTIME
35 0 process owned 7 0 - -
Or in verbose mode :
#ctstat -vi 35
CTID ZONEID TYPE STATE HOLDER EVENTS QTIME NTIME
35 0 process owned 7 0 - -
cookie: 0×20
informative event set: none
critical event set: core signal hwerr empty
fatal event set: none
parameter set: inherit regent
member processes: 658
inherited contracts: none
The HOLDER field indicates that the process holding the contract is having pid 7 :
# ps -fp 7
UID PID PPID C STIME TTY TIME CMD
root 7 1 0 Dec 10 ? 0:41 /lib/svc/bin/svc.startd
which is the main SMF daemon. Let’s find out more about the contract held by this process. The /proc file system
can help there :
# cd /proc/7/contracts/
# ls
17 18 19 22 27 30 32 34 35 36 37 38 39 40 42 43 46 50 83
where we find out why ’svc.startd’, also knows as svc://system/svc/restarter:default is called the master
restarter in the SMF framework : it is holding contracts for many many services.
Coming
back to the verbose output of the ctstat command, we see that some
events received by the holder of contract 35 are considered critical.
Among them, “signal” is an event that indicates the reception of a
fatal signal from another process. The restarter has the job of
restarting syslogd if one ‘critical’ event is received.
Let’s check that…
2. The master restarter
Before helping syslogd to die, let’s open another terminal and type
#ctwatch -rv 35
CTID EVID CRIT ACK CTTYPE SUMMARY
which can be used to see all the events related to contract 35.
We can now use svcadm :
#svcadm refresh system-log
Nothing visible, a quick look at the Pid of syslogd tells us that it only reread its config file. We did the
famous “pkill -HUP syslogd” in the SMF way. Let’s try again :
#svcadm restart system-log
#svcs -pv system-log
STATE NSTATE STIME CTID FMRI
online - 10:24:37 89 svc:/system/system-log:default
10:24:37 2173 syslogd
while the other “ctwatch” terminal shows :
#ctwatch -rv 35
CTID EVID CRIT ACK CTTYPE SUMMARY
35 33 crit no process contract empty
What
happend ? The syslogd process was terminated by svcadm. The contract
being linked to the process is then also terminated and is ‘empty’.
While starting another syslogd, another contract, number 89, was
created.
Now in the “ctwatch” terminal, let’s type
#ctwatch -rv 89
CTID EVID CRIT ACK CTTYPE SUMMARY
while in the other window, we kill the syslog daemon (only in the global zone) :
#pkill -9 -z 0 syslogd
We observe in the “ctwatch terminal” :
#ctwatch -rv 89
CTID EVID CRIT ACK CTTYPE SUMMARY
89 34 crit no process process 2173 received a fatal signal
signal: 9 (SIGKILL)
sender pid: 2187
sender ctid: 86
89 35 crit no process contract empty
Which
shows that the contract subsystem was notified that the syslogd process
received a signal. We even may know who sent it. In our case, it is the
“kill” command, which terminated already. The result of the signal is
that
contract is now empty, ended.
But :
# svcs -pv system-log
STATE NSTATE STIME CTID FMRI
online - 10:27:04 90 svc:/system/system-log:default
10:27:04 2193 syslogd
shows that the master restarter has done its job. The system-log service is still online because “svc.startd” has
instructed “init” to fork and exec a new version of syslogd to keep the service running.
3. The contract file system
Everyone
knows the /proc filesystem, used to provide information to system
administrators about the running processes in a nice well-known
file-based manner. Commands like “ps”, “pfile”, “pgrep”,… get their
information by opening and reading files in /proc which are actually an
interface to the process structures maintained by the kernel.
The
same is true for ctfs, the contract file system. All the contract
commands get their input from the kernel through another pseudo
filesystem mounted on /system/contract.
Example :
# truss -t open ctstat -i 35
open(”/var/ld/ld.config”, O_RDONLY) Err#2 ENOENT
open(”/lib/libcontract.so.1″, O_RDONLY) = 3
open(”/lib/libuutil.so.1″, O_RDONLY) = 3
open(”/lib/libc.so.1″, O_RDONLY) = 3
open(”/lib/libnvpair.so.1″, O_RDONLY) = 3
open(”/lib/libnsl.so.1″, O_RDONLY) = 3
open(”/platform/SUNW,Sun-Blade-100/lib/libc_psr.so.1″, O_RDONLY) = 3
open(”/usr/lib/locale/en_US.ISO8859-1/en_US.ISO8859-1.so.3″, O_RDONLY) = 3
CTID ZONEID TYPE STATE HOLDER EVENTS QTIME NTIME
open64(”/system/contract/all/35/status”, O_RDONLY) = 3
35 0 process owned 7 0 - -
4. Monitor and restart ANY application
The
command ‘ctrun’ can be used to create a contract for any application.
It will then monitor the application process for all the events that
you specify and restart the application if some fatal event occurs.
Check it out!
#ctrun -r 0 -o noorphan -f signal /usr/openwin/bin/xclock &
My
xclock will be restarted any number of times ( -r 0 ), ctrun will make
sure that all processes get killed before restarting ( -o noorphan )
and we monitor the ’signal’ type of fatal event.
You get a contractid and so on.
Then just kill the clock and see it nicely reappear…
1 What is the contract file system?
From contract(4): " The /system/contract file system acts
as the primary interface to the contract subsystem."
From learning solaris
:
"A process contract is the formal definition of the relationship
that exists between a Process A and its monitoring process."
In my own words : "The contract file system sets up a framework
in the kernel that enables real time monitoring of processes and
enables us to act on changes in process states immediately."
2 How to use the contract file system>
The contract file system is primarily used by the SMF(5)
framework when services are started. The service restarter
uses contracts to keep track of the processes in a contract.
It is also possible for applications and users to create
contracts on the fly. The following commands are used by
users to work with and manage contracts:
-
ctstat
-
ctrun
-
ctwatch
-
/system/contract
3 Examine your system
The contract framework is implemented as a pseudo file system.
At system boot the contract file system is mounted at
/system/boot.
www2.petervg.nl # df -n /system/contract
/system/contract : ctfs
www2.petervg.nl # grep ctfs /etc/vfstab
ctfs - /system/contract ctfs - no -
www2.petervg.nl # ls /system/contract//all
22260 22362 6063 6064 6065 6066 6073 6078 6079 6083 6090
6091 6093 6094 6095 6096 6097 6098
4 Create our own contract
With the ctrun
command we can run a
command and place it in a new contract.
4.1 New process without a new contract
www2.petervg.nl # ptree -c $$
14536 zsched
[process contract 22362
]
3168 /usr/lib/ssh/sshd
3171 /usr/lib/ssh/sshd
3173 -bash
3265 sleep 555
3279 ptree -c 3173
www2.petervg.nl # sleep 555 &
[2] 3280
www2.petervg.nl # ptree -c $$
14536 zsched
[process contract 22362
]
3168 /usr/lib/ssh/sshd
3171 /usr/lib/ssh/sshd
3173 -bash
3280 sleep 555
3281 ptree -c 3173
As we can see, the sleep 555
command
is running in the same contract (22362) as the
parent bash
shell.
4.2 New command with a new contract
www2.petervg.nl # ptree -c $$
14536 zsched
[process contract 22362
]
3168 /usr/lib/ssh/sshd
3171 /usr/lib/ssh/sshd
3173 -bash
3300 ptree -c 3173
www2.petervg.nl # ctrun sleep 666 &
[1] 3301
www2.petervg.nl # ptree -c $$
14536 zsched
[process contract 22362
]
3168 /usr/lib/ssh/sshd
3171 /usr/lib/ssh/sshd
3173 -bash
3301 ctrun sleep 666
[process contract 22366
]
3302 sleep 666
3303 ptree -c 3173
And in this example we see that the sleep 666
command is actually run under a new contract (22366).
But does this contract automagically restart the sleep process when
it is killed? The answer is no. By a contract will not restart the
processes in a contract.
5 Checking the status of a contract
When a contract is started we can use the
ctstat
command to get information
about the contract. The
ctwatch
command can then be used
to monitor the use of the contract over time.
www2.petervg.nl # ps -o ctid,pid,ppid,args | grep sleep
22362 3577 3173 ctrun sleep 555
22385 3578 3577 sleep 555
22362 3599 3591 grep sleep
With the ps -o ctid
command it is
possible to identify the contract a particular command is running
in.
www2.petervg.nl # ptree -c $$
14536 zsched
[process contract 22362]
3168 /usr/lib/ssh/sshd
3171 /usr/lib/ssh/sshd
3173 -bash
3591 ksh
4323 ctrun sleep 666
[process contract 22449]
4324 sleep 666
4336 ptree -c 3591
www2.petervg.nl # ctstat -i 22449
CTID ZONEID TYPE STATE HOLDER EVENTS QTIME NTIME
22449 12 process owned 4323 0 - -
In the previous output we see that the contract under investigation
is contract 22449 which is running in zone 12. The current contract
is a process contract which is held by process 4323. This means
that process 4323 created the contract and started the process in
this contract.
With the -v option we can obtain more verbose information about
a specific contract.
www2.petervg.nl # ctstat -v -i 22452
CTID ZONEID TYPE STATE HOLDER EVENTS QTIME NTIME
22452 12 process owned 4408 0 - -
cookie: 0
informative event set: core
critical event set: hwerr empty
fatal event set: hwerr
parameter set: none
member processes: 4409
inherited contracts: none
分享到:
相关推荐
AXI Bridge for PCI Express Gen3 Subsystem v3.0是基于Vivado Design Suite的IP核,旨在提供PCI Express Gen3接口的AXI桥接解决方案。下面是该IP核心的详细知识点总结: 一、AXI Bridge for PCI Express Gen3 ...
解决 Win7 电脑弹出 16 bit MS-DOS Subsystem 的问题 Win7 电脑一直弹出 16 bit MS-DOS Subsystem 的问题是非常常见的,很多用户都遇到过这种情况。这个问题的出现可能是由于系统设置或者恶意软件的影响所致。下面...
s-function subsystem则是将s-function封装为一个子系统,方便在模型中调用和复用。 1. **s-function的概念与分类** - s-function是一种C或MATLAB代码实现的低级别接口,可以替代内置的Simulink模块来执行特定任务...
`mipi_csi2_rx_subsystem` 系统工程正是这样一个实现,它允许FPGA接收来自MIPI CSI-2接口的传感器数据,并可能进一步处理或转发这些数据。 在描述中提到,这个系统已经在`zyqnmp`平台上成功地进行了调试并通过验证...
"subsystem_子系统仿真_"这个标题暗示我们关注的是一个利用仿真工具来研究特定子系统的项目。在这个场景下,学生可能正在使用MATLAB Simulink或者类似的仿真软件进行工程问题的解决,如传热学的一维稳态导热数值计算...
Linux GPIO subsystem
Linux 输入子系统(Input Subsystem)是Linux内核中处理各种输入设备的关键部分,它为键盘、鼠标、触摸屏、游戏控制器等设备提供了一个统一的框架。本篇将深入剖析Linux驱动中的input subsystem机制,通过具体的实例...
To provide researchers and technicians with the tools they need to optimize their role in this communication revolution, the IP Multimedia Subsystem (IMS) Handbookpresents all the technical aspects of...
"Putty.exe to Login Subsystem" 是一个关于使用PuTTY工具进行远程登录操作的主题,特别是针对telnet和SSH协议连接磁盘阵列的实践。PuTTY是一款免费且开源的终端模拟器,它支持多种网络协议,包括Telnet、SSH、...
此文档为XILINX官方对于TSN(时间敏感网络)的集成IP核的用户手册,IP核名称为100M/1G Time Sensitive Networking (TSN) Subsystem,其中集成实现了802.1AS 802.1QBV、802.1QBU等协议。开发平台为vivado。
DMA/Bridge Subsystem for PCI Express v4.1 读书笔记 (中文) XDMA 参考文档:PG195, https://github.com/Xilinx/dma_ip_drivers, https://support.xilinx.com/s/article/65443?language=en_US XDMA IP核的中文...
mac80211是Linux内核中用于处理802.11无线网络硬件的软件堆栈。它设计为一种内核子系统,该子系统通过与低级硬件驱动程序的接口实现部分功能。由于802.11硬件的多样性,mac80211旨在为开发人员提供一个灵活且强大的...
WSL(Windows Subsystem for Linux)是微软公司推出的一种运行在Windows操作系统上的子系统,允许开发者直接在Windows系统上运行GNU/Linux环境,包括大多数命令行工具、实用程序和应用程序,无需经过传统虚拟机或双...
在Xilinx官方文档中(PG210-25G-ethernet)找到自己要的信息,我这里几乎没有去动IP核什么参数,主要是通过这个IP去完成内回环以及外回环的仿真以及上板调试(另一篇文章),通过实现这个去了解整个FPGA开发流程。
根据给定文件的信息,我们可以深入探讨与TMS320相关的知识,特别是关于TMS320DM644xDMSoC中的DSP子系统的关键概念。以下是对标题、描述、标签以及部分内容所涵盖的知识点的详细阐述: ### DSP子系统(TMS320DM644...
This document gives a functional description of the Ethernet Switch Subsystem and related portions of the Serializer/Deserializer (SerDes) module. The Ethernet Switch Subsystem consists of the ...
### TMS320DM646x DMSoC ARM 子系统参考指南知识点解析 #### 一、引言 TMS320DM646x DMSoC ARM 子系统参考指南是一份详尽的技术文档,主要针对德州仪器(Texas Instruments)的DM646x系列达芬奇(DaVinci)芯片中...
Screen Graphics Subsystem is a compositing windowing system that can composite graphics from several different rendering technologies. Screen allows developers to create specific vertical applications...
Subsystem for UNIX-based Applications 中文文件名支持文件 localedef -c -f GBK.cm -i zh_CN.GBK.src -m CP936 zh_CN.GBK export LC_ALL=zh_CN.GBK export LANG=zh_CN.GBK