Linux中wait用法
Linux中wait用法:
系统中的僵尸进程都要由wait系统调用来回收。
函数原型:
#include<sys/types.h>
#include<sys/wait.h>
pid_t wait(int *status);
进程一旦调用了wait就立即阻塞自己,由wait自动分析是否当前进程的某个子进程已经退出,如果让它找到了这样一个已经变成僵尸的子进程,wait就会收集这个子进程的信息,并把它彻底销毁后返回;如果没有找到这样一个子进程,wait就会一直阻塞在这里,直到有一个出现为止。
参数status用来保存被收集进程退出时的一些状态,它是一个指向int类型的指针。但如果我们对这个子进程是如何死掉毫不在意,只想把这个僵尸进程消灭掉,(事实上绝大多数情况下,我们都会这样想),我们就可以设定这个参数为NULL,就像下面这样:
pid = wait(NULL);
如果成功,wait会返回被收集的子进程的进程ID,如果调用进程没有子进程,调用就会失败,此时wait返回-1,同时errno被置为ECHILD。
例子:
/*wait.c*/
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
int main()
{
pid_t pc, pr;
pc = fork();
if ( pc < 0 ) /* 如果出错 */
{
printf("create child prcocess error: %s\n", strerror(errno));
exit(1);
}
else if ( pc == 0) /* 如果是子进程 */
{
printf("I am child process with pid %d \n", getpid());
sleep(3);/* 睡眠3秒钟 */
exit(0);
}
else /* 如果是父进程 */
&nbs
相关文档:
Service Discovery Protocol(SDP)提供一种能力,让应用程序有方法发现哪种服务可用以及这种服务的特性。
服务发现协议(SDP或Bluetooth SDP)在蓝牙协议栈中对蓝牙环境中的应用程序有特殊的含意,发现哪个服务是可用的和确定这些可用服务的特征。SDP定义了bluetooth client发现可用bluetooth server服务和它们的特征的方法。 ......
#wget http://ftp.isc.org/isc/bind9/9.6.1-P1/bind-9.6.1-P1.tar.gz
#tar zxvf bind-9.6.1-P1.tar.gz
#cd bind-9.6.1-P1
#./configure --prefix=/usr/local/named --enable-threads --disable-openssl-version-check --disable-ipv6
#make && make install
#cd /usr/local/named
#sbin/rndc-confgen > e ......
Linux进程间通信的方法
1、管道(pipe)
2、有名管道(named pipe)
3、信号量
4、消息队列
5、信号
6、共享内存
7、套接字
-------------------------------------------------------------------------------
linux进程间通信
1. 管道。
匿名一次性使用的,半双工。一个进程往输出端写管道,另一个进程从 ......
帐号管理
/etc/passwd 系统帐号信息
/etc/shadow 帐号密码信息 经MD5 32位加密
在密码栏前面加『 * 』『 ! 』禁止使用某帐号
/etc/group &nb ......
题目:在Linux下的MATLAB中运行MATLAB程序并在web中显示结果
我做了一个例子主要有5个文件:
webtttt.html webtttt1.html webtttt2.html webtttttempt.html webttttrnd.m
1.webtttt1.html文件
<!-- $Revision: 1.2 $ -->
<HTML>
<HEAD>
<TITLE>Simulat ......