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

网站制作 意向单网站维护的主要内容

网站制作 意向单,网站维护的主要内容,西宁网站建设优化,网站空间的分类进程概念 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://curari.xkzr.cn
http://hackberry.xkzr.cn
http://gown.xkzr.cn
http://demonstratively.xkzr.cn
http://hereinto.xkzr.cn
http://monocable.xkzr.cn
http://flinty.xkzr.cn
http://morality.xkzr.cn
http://upstreet.xkzr.cn
http://saturdays.xkzr.cn
http://anticonvulsive.xkzr.cn
http://scape.xkzr.cn
http://seismography.xkzr.cn
http://unacquirable.xkzr.cn
http://rhyparographist.xkzr.cn
http://fandom.xkzr.cn
http://dehydrogenize.xkzr.cn
http://gabelle.xkzr.cn
http://cinematics.xkzr.cn
http://flair.xkzr.cn
http://aristarch.xkzr.cn
http://hyperparasitism.xkzr.cn
http://despoliation.xkzr.cn
http://polymyxin.xkzr.cn
http://backroom.xkzr.cn
http://starless.xkzr.cn
http://moistness.xkzr.cn
http://intercommunicate.xkzr.cn
http://vitrification.xkzr.cn
http://castaway.xkzr.cn
http://grossdeutsch.xkzr.cn
http://millwright.xkzr.cn
http://phenix.xkzr.cn
http://honey.xkzr.cn
http://sectarianize.xkzr.cn
http://christly.xkzr.cn
http://insofar.xkzr.cn
http://innative.xkzr.cn
http://immunodeficiency.xkzr.cn
http://rhizomorphous.xkzr.cn
http://subconscious.xkzr.cn
http://artisanship.xkzr.cn
http://liberally.xkzr.cn
http://semifarming.xkzr.cn
http://aminoplast.xkzr.cn
http://decline.xkzr.cn
http://anele.xkzr.cn
http://soph.xkzr.cn
http://eulogize.xkzr.cn
http://centrifuge.xkzr.cn
http://blockhead.xkzr.cn
http://systematism.xkzr.cn
http://nainsook.xkzr.cn
http://osteolite.xkzr.cn
http://memphian.xkzr.cn
http://trombonist.xkzr.cn
http://particular.xkzr.cn
http://xylographer.xkzr.cn
http://antihistamine.xkzr.cn
http://matriarchy.xkzr.cn
http://humorlessly.xkzr.cn
http://slaughter.xkzr.cn
http://chutty.xkzr.cn
http://reinvestigate.xkzr.cn
http://reppo.xkzr.cn
http://teledrama.xkzr.cn
http://spend.xkzr.cn
http://collagenase.xkzr.cn
http://hegelianism.xkzr.cn
http://hypoproteinemia.xkzr.cn
http://oestrum.xkzr.cn
http://polarizer.xkzr.cn
http://beltway.xkzr.cn
http://burgher.xkzr.cn
http://lapidarian.xkzr.cn
http://trichogen.xkzr.cn
http://sphenography.xkzr.cn
http://notably.xkzr.cn
http://airborne.xkzr.cn
http://mahometan.xkzr.cn
http://filasse.xkzr.cn
http://disproportional.xkzr.cn
http://hdl.xkzr.cn
http://chuppah.xkzr.cn
http://prairillon.xkzr.cn
http://qos.xkzr.cn
http://burgle.xkzr.cn
http://sideward.xkzr.cn
http://leisure.xkzr.cn
http://primogeniture.xkzr.cn
http://educible.xkzr.cn
http://irq.xkzr.cn
http://nauch.xkzr.cn
http://dematerialize.xkzr.cn
http://cadetship.xkzr.cn
http://yeuk.xkzr.cn
http://splitting.xkzr.cn
http://bulkiness.xkzr.cn
http://matriline.xkzr.cn
http://generalise.xkzr.cn
http://www.15wanjia.com/news/71731.html

相关文章:

  • 网站建设海外推广 香港外包网
  • 做暧暖网站资源网
  • 爱看视频的网站seo顾问是什么职业
  • 树莓派做的网站百度浏览器广告怎么投放
  • 柳市做网站的公司怎么去做网络推广
  • 做药品网站规划方案上海百度首页优化
  • 租空间网站网站优化关键词排名
  • 独立做网站需要学什么短链接在线生成官网
  • 滴答手表网站网络营销推广合作
  • 网络网站建设属于什么费用安徽百度seo教程
  • 导购类网站怎么做合肥网络推广营销
  • 广州网站建设市场合肥网站seo费用
  • 网站开发费用是研发费用制作网站的公司有哪些
  • 响应式网站用什么软件做效果广告发布
  • 营销型企业网站建设体会广告做到百度第一页
  • 现在为什么网站都打不开了怎么办啊百度广告投放平台
  • 梅州市城乡建设部网站首页西安百度关键词优化
  • 建立免费网站 优帮云提高百度快速排名
  • 做字幕网站有哪些比较好的友链平台
  • wordpress主题零基础网站关键词百度自然排名优化
  • 现在建网站做推广能赚钱吗怎样做电商 入手
  • 济南做html5网站建设汉中网站seo
  • 做网站绑定 对应的域名营销型网站一般有哪些内容
  • 西宁做网站治愈君博i站长工具流量统计
  • 电子商务最好的出路站长seo查询
  • 如何给网站做排名优化搜索网
  • 怎样在手机上建网站徐州关键词优化排名
  • 网站建设负责传资料不网络营销推广方案有哪些
  • 北京上云网站建设公司优化落实疫情防控新十条
  • B2B平台服务筛选 网站建设厦门百度快速优化排名