当前位置: 首页 > news >正文

专业做鞋子的网站搜索引擎优化什么意思

专业做鞋子的网站,搜索引擎优化什么意思,大连建设培训网,做网站第一步要干啥对于刚刚接触Unix/Linux操作系统#xff0c;在Linux下编写多进程的人来说#xff0c;fork是最难理解的概念之一#xff1a;它执行一次却返回两个值。 首先我们来看下fork函数的原型#xff1a; #xff03;i nclude sys/types.h #xff03;i nclude unistd.… 对于刚刚接触Unix/Linux操作系统在Linux下编写多进程的人来说fork是最难理解的概念之一它执行一次却返回两个值。   首先我们来看下fork函数的原型   i nclude sys/types.h   i nclude unistd.h   pid_t fork(void);   返回值   负数如果出错则fork()返回-1,此时没有创建新的进程。最初的进程仍然运行。   零在子进程中fork()返回0   正数在负进程中fork()返回正的子进程的PID   其次我们来看下如何利用fork创建子进程。   创建子进程的样板代码如下所示   pid_t child;   if((child fork())0)   /*错误处理*/   else if(child 0)   /*这是新进程*/   else   /*这是最初的父进程*/   fock函数调用一次却返回两次向父进程返回子进程的ID向子进程中返回0   这是因为父进程可能存在很多过子进程所以必须通过这个返回的子进程ID来跟踪子进程   而子进程只有一个父进程他的ID可以通过getppid取得。   下面我们来对比一下两个例子   第一个   #include unistd.h   #include stdio.h   int main()   {   pid_t pid;   int count0;   pid fork();   printf( This is first time, pid %d\n, pid );   printf( This is second time, pid %d\n, pid );   count;   printf( count %d\n, count );   if ( pid0 )   {   printf( This is the parent process,the child has the pid:%d\n, pid );   }   else if ( !pid )   {   printf( This is the child Process.\n)   }   else   {   printf( fork failed.\n );   }   printf( This is third time, pid %d\n, pid );   printf( This is fouth time, pid %d\n, pid );   return 0;   }   运行结果如下     问题   这个结果很奇怪了为什么printf的语句执行两次而那句“count;”的语句却只执行了一次   接着看   #include unistd.h   #include stdio.h   int main(void)   {   pid_t pid;   int count0;   pid fork();   printf( Now, the pid returned by calling fork() is %d\n, pid );   if ( pid0 )   {   printf( This is the parent process,the child has the pid:%d\n, pid );   printf( In the parent process,count %d\n, count );   }   else if ( !pid )   {   printf( This is the child process.\n);   printf( Do your own things here.\n );   count ;   printf( In the child process, count %d\n, count );   }   else   {   printf( fork failed.\n );   }   return 0;   }   运行结果如下   现在来解释上面提出的问题。   看这个程序的时候头脑中必须首先了解一个概念在语句pidfork()之前只有一个进程在执行这段代码但在这条语句之后就变成两个进程在执行了这两个进程的代码部分完全相同将要执行的下一条语句都是if ( pid0 )……。   两个进程中原先就存在的那个被称作“父进程”新出现的那个被称作“子进程”。父子进程的区别除了进程标志符process ID不同外变量pid的值也不相同pid存放的是fork的返回值。fork调用的一个奇妙之处就是它仅仅被调用一次却能够返回两次它可能有三种不同的返回值   1. 在父进程中fork返回新创建子进程的进程ID   2.在子进程中fork返回0   3.如果出现错误fork返回一个负值   fork出错可能有两种原因1当前的进程数已经达到了系统规定的上限这时errno的值被设置为EAGAIN。2系统内存不足这时errno的值被设置为ENOMEM。   接下来我们来看看APUE2中对fork的说明   The new process created by fork is called the child process. This function is called once but returns twice. The only difference in the returns is that the return value in the child is 0, whereas the return value in the parent is the process ID of the new child. The reason the childs process ID is returned to the parent is that a process can have more than one child, and there is no function that allows a process to o^ain the process IDs of its children. The reason fork returns 0 to the child is that a process can have only a single parent, and the child can always call getppid to o^ain the process ID of its parent. (Process ID 0 is reserved for use by the kernel, so its not possible for 0 to be the process ID of a child.)   被fork创建的新进程叫做自进程。fork函数被调用一次却两次返回。返回值唯一的区别是在子进程中返回0而在父进程中返回子进程的pid。在父进程中要返回子进程的pid的原因是父进程可能有不止一个子进程而一个进程又没有任何函数可以得到他的子进程的pid。   Both the child and the parent continue executing with the instruction that follows the call to fork. The child is a copy of the parent. For example, the child gets a copy of the parents data space, heap, and stack. Note that this is a copy for the child; the parent and the child do not share these portions of memory. The parent and the child share the text segment (Section 7.6).   子进程和父进程都执行在fork函数调用之后的代码子进程是父进程的一个拷贝。例如父进程的数据空间、堆栈空间都会给子进程一个拷贝而不是共享这些内存。   Current implementations dont perform. a complete copy of the parents data, stack, and heap, since a fork is often followed by an exec. Instead, a technique called copy-on-write (COW) is used. These regions are shared by the parent and the child and have their protection changed by the kernel to read-only. If either process tries to modify these regions, the kernel then makes a copy of that piece of memory only, typically a page in a virtual memory system. Section 9.2 of Bach [1986] and Sections 5.6 and 5.7 of McKusick et al. [1996] provide more detail on this feature.   我们来给出详细的注释   #include unistd.h   #include stdio.h   int main(void)   {   pid_t pid;   int count0;   /*此处执行fork调用创建了一个新的进程 这个进程共享父进程的数据和堆栈空间等这之后的代码指令为子进程创建了一个拷贝。 fock 调用是一个复制进程fock 不象线程需提供一个函数做为入口 fock调用后新进程的入口就在 fock的下一条语句。*/   pid fork();   /*此处的pid的值可以说明fork调用后目前执行的是父进程还是子进程*/   printf( Now, the pid returned by calling fork() is %d\n, pid );   if ( pid0 )   {   /*当fork在子进程中返回后fork调用又向父进程中返回子进程的pid 如是该段代码被执行但是注意的事count仍然为0 因为父进程中的count始终没有被重新赋值,  这里就可以看出子进程的数据和堆栈空间和父进程是独立的而不是共享数据*/   printf( This is the parent process,the child has the pid:%d\n, pid );   printf( In the parent process,count %d\n, count );   }   else if ( !pid )   { /*在子进程中对count进行自加1的操作但是并没有影响到父进程中的count值父进程中的count值仍然为0*/   printf( This is the child process.\n);   printf( Do your own things here.\n );   count;   printf( In the child process, count %d\n, count );   }   else   {   printf( fork failed.\n );   }   return 0;   }   也就是说在Linux下一个进程在内存里有三部分的数据就是代码段、堆栈段和数据段。代码段顾名思义就是存放了程序代码的数据假如机器中有数个进程运行相同的一个程序那么它们就可以使用相同的代码段。堆栈段存放的就是子程序的返回地址、子程序的参数以及程序的局部变量。而数据段则存放程序的全局变量常数以及动态数据分配的数据空间比如用malloc之类的函数取得的空间。系统如果同时运行数个相同的程序它们之间就不能使用同一个堆栈段和数据段。 转载于:https://blog.51cto.com/k21ye/885485
http://www.huolong8.cn/news/215631/

相关文章:

  • 深圳网站优化包年网站视觉规范怎么做
  • 网站建设考试知识点APP网站开发私人订制
  • 贵州专业建网站哪里有做投票的网站
  • 如何删除网站备案号wordpress字体抖动
  • 地方招聘网站如何做推广网站多数关键词
  • 网站域名怎么免费获取5000元可注册劳务公司吗
  • 国外网站做freelancer电子商务做网站设计
  • 织梦移动端网站建设做网站教学
  • 恒基建设集团网站广东网页设计
  • 济南网站制做网站建设通报
  • 荆州做网站公司郑州百度网站建设
  • 企业网站一般内容包括哪些wordpress文章默认经典
  • 医院可以做网站吗在本地做装修在那个网站好
  • 网站搜索引擎关键字怎么做网站建设w亿玛酷1流量订制
  • 做网站什么语言最好青海省公路建设管理局官方网站
  • 上海市建设安全协会官方网站企业信用信息查询公示系统浙江
  • 营销型公司网站佛山网站建设公司大全
  • 网页制作与设计站点应该怎么建手机网站开发解决方案
  • 马鞍山网站设计价格游戏网站怎么赚钱
  • 网络营销推广的概念鲨皇seo
  • 学校网站建设整改报告有做网站设计的吗
  • 做网站需要注意事项哈尔滨做网站建设
  • 南京疾控最新通告今天网站搜索引擎优化工具
  • apache添加网站网页版传奇有哪些
  • 网上做图赚钱的网站用网站做淘客怎么做
  • 推荐做微商海报的网站怀化市建设局门户网站
  • 邯郸开发网站有哪些网站包括哪些内容
  • 广西医院响应式网站建设方案网店服务平台
  • 专门做网站的公司与外包公司有哪些学校网站制作素材
  • 广州市做网站的桂林到阳朔多少公里