- 浏览: 266549 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
AndMacLinuXp:
试了下,不错!
printk内核调试 -
klose:
我引用你的文章,并做了简单的分析:这里贴出url:http:/ ...
linux系统调用fork, vfork, clone -
klose:
你上面提到的问题:free的问题。首先你可能疏忽了,stack ...
linux系统调用fork, vfork, clone -
qwe_rt:
HI ,非常nice的文章,在阅读过程中,我发现我的ubunt ...
linux手动添加开机启动的服务 -
suifeng:
谢谢分享, 受用中.
shell编程分支,循环
wait4会挂起当前进程,等待指定的子进程状态改变,并且会返回关于子进程使用资源的信息。所谓的状态的改变包括终止,挂起所有的进程状态的改变。
其次,在linux中进程终止后不会释放其资源,它会进入一种僵死的状态,内核会为僵死态的进程保留最少的信息(进程标识,终止状态和资源使用信息).而wait4就可以释放与子进程关联的资源。如果父进程不执行wait,而父进程又死亡后,僵死态的子进程会被指定成系统初始化进程init的子进程.下面是wait4使用方法:
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage);
pid是要关注的子进程的pid(进程标识号)
status子进程的返回状态。
options进程等待选项
rusage死亡进程资源使用记录
pid这个很好理解,进程标识号,也是你ps -le显示出来的pid。如果指定了pid则会在指定pid发生变化后唤醒父进程,此外还有一下4种情况:
< -1 which means to wait for any child process whose process group ID is equal to the absolute value of pid.
-1 which means to wait for any child process; this is equivalent to calling wait3.
0 which means to wait for any child process whose process group ID is equal to that of the calling process.
> 0 which means to wait for the child whose process ID is equal to the value of pid.
status子进程的返回状态,这是个用于描述进程返回状态的整数,有各种宏操作可以查看,如下:
WIFEXITED(status)
is non-zero if the child exited normally.
WEXITSTATUS(status)
evaluates to the least significant eight bits of the return code of the child which terminated, which may have been set as the argument to a call
to exit() or as the argument for a return statement in the main program. This macro can only be evaluated if WIFEXITED returned non-zero.
WIFSIGNALED(status)
returns true if the child process exited because of a signal which was not caught.
WTERMSIG(status)
returns the number of the signal that caused the child process to terminate. This macro can only be evaluated if WIFSIGNALED returned non-zero.
WIFSTOPPED(status)
returns true if the child process which caused the return is currently stopped; this is only possible if the call was done using WUNTRACED.
WSTOPSIG(status)
returns the number of the signal which caused the child to stop. This macro can only be evaluated if WIFSTOPPED returned non-zero.
options进程等待选项,当为WNOHANG表示立即返回,而当WUNTRACED表示等子进程状态发生变化后才返回。
最后rusage记录死亡进程资源使用信息,这个数据结构定义如下:
struct rusage {
struct timeval ru_utime; /* user time used */
struct timeval ru_stime; /* system time used */
long ru_maxrss; /* maximum resident set size */
long ru_ixrss; /* integral shared memory size */
long ru_idrss; /* integral unshared data size */
long ru_isrss; /* integral unshared stack size */
long ru_minflt; /* page reclaims */
long ru_majflt; /* page faults */
long ru_nswap; /* swaps */
long ru_inblock; /* block input operations */
long ru_oublock; /* block output operations */
long ru_msgsnd; /* messages sent */
long ru_msgrcv; /* messages received */
long ru_nsignals; /* signals received */
long ru_nvcsw; /* voluntary context switches */
long ru_nivcsw; /* involuntary context switches */
};
使用样例
[root@liumengli wait]# cat print.c
#include "stdio.h"
int main() {
int i;
for (i = 0; i < 50; i++)
printf("Hello, This is print!!!\n");
exit(0);
}
[root@liumengli wait]# gcc print.c -o print
[root@liumengli wait]# cat test_wait.c
#include "stdio.h"
#include <sys/types.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
int main() {
int child;
int * status;
struct rusage * rus;
char * argu[] = {"/program/wait/print", NULL};
if(!(child = vfork())) {
execve("/program/wait/print", argu, NULL);
} else {
wait4(child,status,WUNTRACED,rus);
printf("The son's pid:%d, status:%d, The memory is:%d\n", child, WIFEXITED(status),rus->ru_nswap);
}
exit(0);
}
[root@liumengli wait]# gcc test_wait.c -o test_wait
[root@liumengli wait]# ./test_wait
Hello, This is print!!!
Hello, This is print!!!
Hello, This is print!!!
Hello, This is print!!!
.......
Hello, This is print!!!
Hello, This is print!!!
Hello, This is print!!!
Hello, This is print!!!
The son's pid:3237, status:0, The memory is:-1996293951
[root@liumengli wait]#
发表评论
-
linux下挂在windows共享文件夹
2012-05-06 12:53 846smbmount //nas/xxxx /mnt/nas -o ... -
进程组 对话期
2010-04-16 16:12 1345为了便于进程控制,于是就有了进程组,对话期的概念。 进 ... -
感谢你教会我如何提问-《提问的智慧》
2009-01-12 11:25 1414转自:http://linux.chinaunix ... -
linux手动添加开机启动的服务
2009-01-02 14:48 7154如果你只是想知道如何 ... -
让信号量来实现临界区控制
2008-12-09 16:14 1557前面我们谈到过管道,消息队列。我们可以使用他们可以解决了2个进 ... -
进程通行之报文消息队列
2008-12-04 17:39 1367报文和消息队列又是进 ... -
信号和信号处理
2008-11-26 16:09 3307信号同样是用于进程通 ... -
命名管道实现样例
2008-11-18 17:41 1242[root@liumengli name_pipe]# mkn ... -
linux中的管道实现和管道
2008-11-14 17:52 12943inux的shell中有个很常用的东西管道,很多人认为他是sh ... -
文件访问权限和安全
2008-10-28 18:02 1172打开文件,读取内容或 ... -
printk内核调试
2008-10-15 17:07 9381首先阐明一点,我调试的目的是为了学习,看看内核代码是如何运行, ... -
linux内核编译
2008-10-07 17:36 1924这是调试linux内核的必要步骤,虽然很麻烦,而且容易出错(所 ... -
linux文件系统
2008-10-06 11:08 964文件系统是一个比较模糊的名词,文件也是一个比较模糊的名词。狭义 ... -
linux内核书籍下载
2008-09-25 11:47 2117学习内核代码之前,需要有以下一些基础: 1.linux系统管理 ... -
nanosleep函数
2008-09-24 17:36 3331int nanosleep(const struct ti ... -
linux进程调度政策
2008-09-23 11:45 1545进程调度政策就是调度系统种哪一个进程来CPU运行。这种调度分2 ... -
linux进程调度发生的时机
2008-09-19 18:03 4087所谓调度时机就是:什么时候会发生进程调度。在linux中,进程 ... -
SSH远程启动服务的问题
2008-09-18 12:32 4684SSH是我们最长用的远程连接linux服务器的工具了,安全 ... -
时钟中断
2008-09-17 16:57 3339时钟中断:是指在计算 ... -
wait4的实现
2008-09-17 15:38 2938不贴实现的代码了,很 ...
相关推荐
Chapter 4: CPU-Related Wait Types Chapter 5: IO-Related Wait Types Chapter 6: Backup-Related Wait Types Chapter 7: Lock-Related Wait Types Chapter 8: Latch-Related Wait Types Chapter 9: High-...
资源分类:Python库 所属语言:Python 资源全名:wait4it-0.2.1.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源来自pypi官网。 资源全名:wait4it-0.2.1-py3-none-any.whl
fast-wait-free-queue, 并发队列实现的基准框架 快速等待空闲队列这是评估并发队列性能的基准测试框架。 目前,它包含4 个并发队列。 它们是:一个快速等待队列 wfqueueafek的Morrison和 lcrqkallimanis的Fatourou和...
#0 0x00002b9405ea1c38 in __lll_mutex_lock_wait () from /lib64/libc.so.6 #1 0x00002b9405e45e5f in _L_lock_4026 () from /lib64/libc.so.6 #2 0x00002b9405e42df1 in free () from /lib64/libc.so.6 #3 0x00002...
4.sleep必须捕获异常,而wait,notify和notifyAll不需要捕获异常。(如果不是在同步方法或同步代码块中调用wait()方法,则抛出IllegalMOnitorStateException,它是RuntimeException的一个子类,因此,不需要try-...
国内某软件公司文件:Delphi开发代码规范(修改),
1. 主动关闭连接的 - 也就是主动调socket的close操作的,最终 2. 被动关闭连接的,有个中间状态,即CLOSE_WAIT,因为协议 4. 在个连接
wait4ports 一个等待网络对等可用性的小... 如果设置为0,则不使用超时,并且wait4ports将永远等待。环境也可以通过环境变量启用选项: WAIT4PORTS_VERBOSE : 默认情况下,详细程度为打开状态,但是将此值设置为0 ,
stm32f4通过spi用fatfs读写sd卡程序,已经调通。用的是单片机中B口的B11--CS、B13--SCLK、B14--MISO、B15--MOSI.
wait4it 一个简单的go应用程序,用于测试端口是否已准备好接受连接或检查MySQL,PostgreSQL,MongoDB或Redis服务器是否已就绪。您还可以执行Http调用并检查响应代码和响应文本。 它还支持超时,因此可以等待特定...
4.只在设计上遵循了AMD规范,但是使用上却使用了类似CMD规范。我和我的团队都喜欢在require时暴露出过程,会比较灵活。可以伴随逻辑require,而不是预先require好资源再执行。 5.目前只支持到ie8。 6.支持加载css...
4、使用fork,exec以及wait函数构造简单的shell解释程序。(15分) (1) 假定所编辑的c程序为myxsh.c,使用命令行方式将该源程序编译,目标执行程序为myxsh。给出具体的编译实现过程。 (2) 假定当前目录下有文件信息...
利用 mach_wait_until 的精确计时器 要求 iOS:iOS 4 MacOS X:Mac OS X 10.6 演示 iOS 应用程序使用 Xcode 6.1 制作并针对 iOS 8 如果您在商业项目中使用它,请在 README 或 About Box 中提供署名。
思科推荐的排错流量: ①ping直连测试,如果不通,就检查接口配置。 ②查看路由,如果没有就写静态或者动态。...④使用Capture分别抓取收包和发包接口的数据,进行对比(ASA自带程序),这也是终极解决方案。
tcp4 0 0 127.0.0.1.50937 127.0.0.1.8383 CLOSE_WAIT 这次我们了解到的是,只有在应用程序显式调用close或终止应用程序时,才可以接收等待CLOSE_WAIT的关闭。 因此,如果您在这种CLOSE_WAIT状态下无限期地等待,...
1.notify的使用 2. wait的使用 3. linux系统下的开发 4.多线程通信 5. 生产者和消费者模式
uses : armory-io/spin-wait-status-action@master with : baseUrl : ' http://examplebaseUrl ' application : ' example-app ' eventId : ' 7ab2d981-430a-44e9-8f4e-77f96593e004 ' crtFile : ' SG
0 该模块允许丢弃TCP连接,可用于终止TIME-WAIT套接字。 用法 首先编译并加载模块: ... # netstat -n -t | grep WAIT | awk '{print $4"\t"$5}' 127.0.0.1:41278 127.0.0.1:22 127.0.0.1:41276 127.0.0.1:22 127.0