当前位置: 首页 > 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://www.yayakq.cn/news/728978/

相关文章:

  • 建设风景网站策划书婚礼模板
  • 自建网站营销网络搜索工具
  • 个人空间网站模板做网站开发服务商
  • 如何开发自己的网站网站代发怎么做
  • 青岛制作网站软件国外网站的分析工具有哪些
  • 哈尔滨网站建设教学汕头网站外包
  • 沈阳求做商城 网站学校介绍网站模板
  • 双语网站建设哪家便宜网站后台验证码不正确
  • 网站开发成本计算网站app的区别是什么意思
  • 大连三合一网站制作制作视频用什么软件
  • 中小企业网站建设与推广wordpress资源
  • 找做钢筋笼的活网站做网站开发需要什么
  • 杭州网站开发设计各国网站的域名
  • 英文网站的建设合肥网站排名推广
  • 网站改版 需求文档万网创始人为什么封停慧聪网
  • 做网站 教程谷歌google官方下载
  • 青海省建设工程造价网站asp.net做网站吗
  • 交互网站开发培训wordpress文章怎么加关键词描述
  • 网站建设三站合一微信小程序天津网上办事大厅入口
  • 科技园区建设网站的意义百度学术搜索
  • 企业网站建设要点策划书word模板范文
  • 便宜网站建设模板网站小程序推广有哪些好的方法
  • 公司开发网站关键词的选择网站提示
  • 简约个人网站馨雨公司网站建设策划方案
  • 做网站卖资料达州建设机械网站
  • 抄袭网站后台会侵权吗公司网站制作有哪些注意事项
  • 做推广哪个网站最好电子商务类网站设计
  • 哔哩哔哩网站建设模板怎样做3d动画短视频网站
  • 汕头整站优化wordpress无法超链接
  • 山石网站超市网络推广的基本方法