【IT168 技术】 一个进程,包括代码、数据和分配给进程的资源。fork()函数通过系统调用创建一个与原来进程几乎完全相同的进程,也就是两个进程可以做完全相同的事,但如果初始参数或者传入的变量不同,两个进程也可以做不同的事。
一个进程调用fork()函数后,系统先给新的进程分配资源,例如存储数据和代码的空间。然后把原来的进程的所有值都复制到新的新进程中,只有少数值与原来的进程的值不同。相当于克隆了一个自...
阅读全文
【IT168 技术】 #include ;
#include ;
main ()
{
pid_t pid;
pid=fork();
if (pid < 0)
printf("error in fork!");
else if (pid == 0)
printf("i am the child process, my process id is %dn",getpid());
else
printf("i am the parent process, my process id is %dn",getpid());
}
结果是
[root@localhost c]# ./a.out
i am the child process, my pr...
阅读全文
用函数模板实现和优化抽象操作
作者:Danny Kalev编译:MTT 工作室
原文出处:Optimize Abstract Operations with Function Templates
摘要:本文介绍函数模板的概念、用途以及如何创建函数模板和函数模板的使用方法......
在创建完成抽象操作的函数时,如:拷贝,反转和排序,你必须定义多个版本以便能处理每一种数据类型。以 max() 函数为例,它返回两个参数中的较大者:
double max(double first, double seco...
阅读全文
(转,网络资源)
函数说明对于FTP 文件传输,采用C++的类来实现,定义了一个FTPClient 的C++类,在该类对象定义了6 个公共函数:Init( )、SendFile( )、ReceiveFile( )、Do( )、Resume( )和Stop( )函数。下面对各个函数作详细介绍。(1) int Init(char *host, char *FTPusername, char *FTPpassword, unsignedlong timeout, int FTPMode );功能描述:初始化设置FTP 文件传输参数。输入参数:英创信息技术有限公司 嵌入式系统...
阅读全文
如何编写异常安全的C++代码
出处:不亦快斋 作者:非典型秃子
关于C++中异常的争论何其多也,但往往是一些不合事实的误解。异常曾经是一个难以用好的语言特性,幸运的是,随着C++社区经验的积累,今天我们已经有足够的知识轻松编写异常安全的代码了,而且编写异常安全的代码一般也不会对性能造成影响。
使用异常还是返回错误码?这是个争论不休的话题。大家一定听说过这样的说法:只有在真正异常的时候,...
阅读全文
1、DateTime 数字型 System.DateTime currentTime=new System.DateTime(); 1.1 取当前年月日时分秒 currentTime=System.DateTime.Now; 1.2 取当前年 int 年=currentTime.Year; 1.3 取当前月 int 月=currentTime.Month; 1.4 取当前日 int 日=currentTime.Day; 1.5 取当前时 int 时=currentTime.Hour; 1.6 取当前分 int 分=currentTime.Minute; 1.7 取当前秒 int 秒=currentTime.Second; 1.8 取当前毫秒 int 毫秒=currentTime.Mi...
阅读全文
/*This is a sample routine of ping.It's implemented with winsock1.1 * under windows 2000 professional and has been not tested under other * platform.Our target is to illustrator the principles,so many details* may be ignored.(author email:zhangwu2003@163.com)*/#include<stdio.h>#include<windows.h>#include<process.h>
#define SEND_SIZE 32 #define PACKET_SIZE 4096#define ICMP_ECH...
阅读全文