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

as3.0网站制作教程如何制作网页设计

as3.0网站制作教程,如何制作网页设计,手游推广渠道,html展示网站源代码进程概念 ps -elf:查看操作系统的所有进程(Linux命令) ctrl z:把进程切换到后台 crtl c:结束进程 fg:把进程切换到前台 获取进程进程号和父进程号 函数原型: pid_t getpid(void); //pid_t…

进程概念

ps -elf:查看操作系统的所有进程(Linux命令)
ctrl + z:把进程切换到后台
crtl + c:结束进程
fg:把进程切换到前台

获取进程进程号和父进程号

函数原型:

pid_t getpid(void); //pid_t,它是一个有符号整数类型。
pid_t getppid(void);

例子:

#include <stdio.h>                                                                                                                                  
#include <sys/types.h>
#include <unistd.h>int main()
{pid_t pid = getpid();printf("当前进程的进程号为:%d\n", pid);pid_t ppid = getppid();printf("当前进程的父进程为:%d\n", ppid);while(1);return 0;
}

fork

概念:fork() 是一个在操作系统编程中常用的函数,用于创建一个新的进程。它通过复制调用进程(称为父进程)来创建一个新的进程(称为子进程)。子进程是父进程的副本,它从 fork() 函数返回的地方开始执行。
在这里插入图片描述

以下是 fork() 函数的原型:

#include <sys/types.h>
#include <unistd.h>
pid_t fork(void);

fork() 函数没有参数,它返回一个 pid_t 类型的值,表示进程的状态。返回值有以下几种情况:

  • 如果返回值是负数(-1),则表示创建子进程失败。
  • 如果返回值是零(0),则表示当前代码正在子进程中执行。
  • 如果返回值是正数,则表示当前代码正在父进程中执行,返回值是新创建子进程的PID。

例子:

#include <stdio.h>                                                                                                                                  
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>int main()
{       pid_t pid = fork();if(pid == -1){perror("fork");exit(1);}else if(pid == 0){       printf("child pid=%d, getpid=%d, getppid=%d\n", pid, getpid(), getppid());
//      while(1)
//      {printf("child\n");sleep(1);
//      }}else    {       printf("parent pid=%d, getpid=%d, getppid=%d\n", pid, getpid(), getppid());
//      while(1)
//      {printf("parent\n");sleep(2);
//      }}printf("helloworld\n");//会输出两次return 0;
}      

fork笔试题

详情看下述代码:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>int main()
{for(int i = 0; i < 2; i++){   fork();//  printf("-\n"); //6个"-",换行符会输出缓冲区里的的数据printf("-"); // 8个"-",子进程会复制父进程输出缓冲区的数据}   return 0;
}

在这里插入图片描述
在这里插入图片描述

fork原理

在这里插入图片描述
下面输出都为1的原因是,父子进程在不同的空间

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>int main()
{                                                                                                                                                   int num = 0;if(fork() == 0){   num++;printf("child %d\n", num);}   else{   num++;printf("parent %d\n", num);}/*输出为:child 1parent 1*/return 0;}

多进程读写

#include <stdio.h>                                                                                                                                  
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>void child_write(int fd)
{char buf[128] = {0};while(1){scanf("%s", buf);if(write(fd, buf, strlen(buf)) == -1){perror("write");break;}lseek(fd, -1 * strlen(buf), SEEK_CUR);if(!strcmp(buf, "bye"))break;memset(buf, 0, 128);}//i lseek(fd, -1 * strlen(buf), _CUR);}void parent_read(int fd)
{char buf[128] = {0};while(1){int ret = read(fd, buf, sizeof(buf));if(ret == -1){perror("read");break;}else if(ret == 0)continue;if(!strcmp(buf, "bye"))break;printf("child get: %s\n", buf);memset(buf, 0, sizeof(buf));}
}int main()
{int fd = open("hello.txt", O_CREAT | O_RDWR, 00400 | 00200);if(-1 == fd){perror("open");exit(1);}if(fork() == 0){child_write(fd);}else{parent_read(fd);}close(fd);return 0;
}          
http://www.15wanjia.com/news/52349.html

相关文章:

  • 阿里做网站如何获取永久免费域名
  • 古典 网站模板seo高端培训
  • 新吴区推荐做网站公司网站网络推广
  • 用路由器做网站太原seo排名外包
  • 网站实名制认证备案域名ip查询入口
  • WordPress 整合源码泉州百度seo公司
  • 淘宝客网站怎么做推广好用的seo软件
  • wordpress更改页脚社交图标seo是什么软件
  • 做电影网站要怎么样的主机南京搜索引擎推广优化
  • wordpress 自定义页面模版长沙seo关键词排名
  • wordpress 站内信 群发夫唯seo教程
  • 图书馆 网站建设seo外链自动群发工具
  • 想做电商怎么注册外贸建站优化
  • 做内部优惠券网站赚钱吗南昌百度搜索排名优化
  • 做网站延期交付了网站建设包括哪些内容
  • 做网站 买空间怎么做网址
  • 挂马网站教程百度搜索风云榜排行榜
  • 东莞响应式网站制作网优工程师前景和待遇
  • 建设一个视频网站个人免费开发app
  • 个人做百度云下载网站长沙百度关键词搜索
  • jsp网站开发关键技术优化大师win7
  • 怎么样给公司做网站国内哪个搜索引擎最好用
  • 网站建设有前途数字化营销怎么做
  • 宠物网站设计模块石狮seo
  • 阜蒙县建设小学校官方网站如何写好一篇软文
  • 自媒体专业搜索引擎优化面对哪些困境
  • 网站分析百度it教育培训机构排名
  • 建立门户网站的程序百度推广最近怎么了
  • 爱奇艺会员做任务送十天网站搜索引擎技术优化
  • 阿里网站建设湖南专业关键词优化