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
¡¡¡¡×÷Ó㺵Ǽµ½·þÎñÆ÷Ö ......
1
¸ùÎļþϵͳ
¼òµ¥À´Ëµ£¬£¨¸ùÎļþϵͳ£©¾ÍÊÇϵͳµÚÒ»¸ö
mount
µÄÎļþϵͳ
Filesystem
Handling
Like
every
traditional
Unix
system,
Linux
makes
use
of
a
system ......
×¼±¸¹¤×÷£º
1.Xming£¨windowsÔËÐÐx-windowsµÄÖ§³Ö£©
2.SecureCRTV6.5.8.380ºº»¯ÂÌÉ«Æƽâ°æ
¿ÉÒÔÈ¥ÎÒµÄhttp://download.csdn.net/johnvikeyÏÂÔØ
Èç¹ûÊÇÃüÁîÐÐÖ±½ÓÓÃ
SecureCRT
Èç¹ûÊÇÒªÔËÐÐͼÐγÌÐò
1.Xming£¨windowsÔËÐÐx-windowsµÄÖ§³Ö£©
2.SecureCRTV6.5.8.380ºº»¯ÂÌÉ«Æƽâ°æ
¶¼ÒªÊ¹ÓÃ
———&m ......
SystemTap ÊǼà¿ØºÍ¸ú×ÙÔËÐÐÖÐµÄ Linux Äں˵IJÙ×÷µÄ¶¯Ì¬·½·¨¡£Õâ¾ä»°µÄ¹Ø¼ü´ÊÊǶ¯Ì¬£¬ÒòΪ SystemTap ûÓÐʹÓù¤¾ß¹¹½¨Ò»¸öÌØÊâµÄÄںˣ¬¶øÊÇÔÊÐíÄúÔÚÔËÐÐʱ¶¯Ì¬µØ°²×°¸Ã¹¤¾ß¡£Ëüͨ¹ýÒ»¸öÃûΪKprobes µÄÓ¦Óñà³Ì½Ó¿Ú£¨API£©À´ÊµÏÖ¸ÃÄ¿µÄ£¬±¾ÎĽ«Ì½Ë÷Õâ¸ö API¡£ÎÒÃÇÊ×ÏÈÁ˽âÒÔÇ°µÄһЩÄں˸ú×Ù·½·¨£¬È»ºóÔ ......
ͨÐÅ
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 ......