linux C forkº¯Êý
´´½¨Ð½ø³Ì£ºforkº¯Êý
1.1.1. forkº¯Êý¸Éʲô£¿
#include <sys/types.h>
#include <unistd.h>
pid_t fork(void);
‘fork()’º¯ÊýÓÃÓÚ´ÓÒÑ´æÔÚ½ø³ÌÖд´½¨Ò»¸öнø³Ì¡£Ð½ø³Ì³ÆΪ×Ó½ø³Ì£¬¶øÔ½ø³Ì³ÆΪ¸¸½ø³Ì¡£Äã¿ÉÒÔͨ¹ý¼ì²é‘fork()’º¯ÊýµÄ·µ»ØÖµÖªµÀÄĸöÊǸ¸½ø³Ì£¬ÄĸöÊÇ×Ó½ø³Ì¡£¸¸½ø³ÌµÃµ½µÄ·µ»ØÖµÊÇ×Ó½ø³ÌµÄ½ø³ÌºÅ£¬¶ø×Ó½ø³ÌÔò·µ»Ø0¡£ÒÔÏÂÕâ¸ö·¶Àý³ÌÐò˵Ã÷ËüµÄ»ù±¾¹¦ÄÜ£º
pid_t pid;
switch (pid = fork())
{
case -1:
/* ÕâÀïpidΪ-1£¬forkº¯Êýʧ°Ü */
/* һЩ¿ÉÄܵÄÔÒòÊÇ */
/* ½ø³ÌÊý»òÐéÄâÄÚ´æÓþ¡ */
perror("The fork failed!");
break;
case 0:
/* pidΪ0£¬×Ó½ø³Ì */
/* ÕâÀÎÒÃÇÊǺ¢×Ó£¬Òª×öʲô£¿ */
/* ... */
/* µ«ÊÇ×öÍêºó, ÎÒÃÇÐèÒª×öÀàËÆÏÂÃ棺 */
_exit(0);
default:
/* pid´óÓÚ0£¬Îª¸¸½ø³ÌµÃµ½µÄ×Ó½ø³ÌºÅ */
printf("Child's pid is %d\n",pid);
}
µ±È»£¬ÓÐÈË¿ÉÒÔÓÑif() ... else ...’Óï¾äÈ¡´ú‘switch()’Óï¾ä£¬µ«ÊÇÉÏÃæµÄÐÎʽÊÇÒ»¸öÓÐÓõĹßÓ÷½·¨¡£
ÖªµÀ×Ó½ø³Ì×Ô¸¸½ø³Ì¼Ì³Ðʲô»òδ¼Ì³Ðʲô½«ÓÐÖúÓÚÎÒÃÇ¡£ÏÂÃæÕâ¸öÃûµ¥»áÒòΪ²»Í¬UnixµÄʵÏÖ¶ø·¢Éú±ä»¯£¬ËùÒÔ»òÐí׼ȷÐÔÓÐÁËË®·Ý¡£Çë×¢Òâ×Ó½ø³ÌµÃµ½µÄÊÇÕâЩ¶«Î÷µÄ *¿½±´*£¬²»ÊÇËüÃDZ¾Éí¡£
ÓÉ×Ó½ø³Ì×Ô¸¸½ø³Ì¼Ì³Ðµ½£º
½
Ïà¹ØÎĵµ£º
¡¡¡¡×ܽáһЩ³£ÓõÄLinuxÃüÁî¡£
Ò»¡¢LinuxÄں˺Ͱ汾²éѯÃüÁî
¡¡¡¡ÃüÁ uname -a
¡¡¡¡×÷Ó㺠²é¿´ÏµÍ³Äں˰汾ºÅ¼°ÏµÍ³Ãû³Æ¡£
¡¡¡¡ÃüÁ cat /proc/version
¡¡¡¡×÷Ó㺠²é¿´Ä¿Â¼"/proc"ÏÂversionµÄÐÅÏ¢£¬Ò²¿ÉÒԵõ½µ±Ç°ÏµÍ³µÄÄں˰汾ºÅ¼°ÏµÍ³Ãû³Æ¡£
¡¡¡¡ÃüÁlsb_release -a
¡¡¡¡×÷Ó㺵Ǽµ½·þÎñÆ÷Ö ......
º¯ÊýÃû: abs ¹¦ ÄÜ: ÇóÕûÊýµÄ¾ø¶ÔÖµ
ÓÃ ·¨: int abs(int i);
³ÌÐòÀý:
#include <stdio.h>
#include <math.h>
int main(void)
{
int number = -1234;
printf("number: %d absolute value: %d\n", number, abs(number));
return 0;
}
º¯ÊýÃû: atof
¹¦ ......
ͨÐÅ
Server£º
#pragma comment(lib, "ws2_32.lib")
#include <Winsock2.h>
#include <stdio.h>
void main()
{
//°æ±¾ÐÉÌ
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(1,1); //0x0101
err = WSAStartup ......
nokia wiki£ºhttp://developer.symbian.org/wiki/index.php/Open_C_and_Open_C%2B%2B_Technical_Overview/zh-hans
symbianÉÏ¿ª·¢opencʱÐèҪעÒâµÄÎÊÌâ
http://blog.csdn.net/sizhiguo/archive/2009/05/21/4206138.aspx
µÚÒ»£ºÈçprintf¡¢sprint¡¢Îļþ²Ù×÷¡¢socket²Ù×÷µÈ£¬Ä£ÄâÆ÷ÆÁÄ»¶¼»á³öÏÖ°×ÆÁµÈ´ý£¬²¢ÇÒÊÇÒ»Ö±ÏÂÈ¥¡£ ......