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

报电子商务(网站建设与运营)客户管理软件

报电子商务(网站建设与运营),客户管理软件,网站建设教程参加苏州久远网络,php网站的后台地址​​ 一、软件需求 在同时运行多个CPU密集型进程时,需采集以下统计信息: 当前运行在逻辑CPU上的进程ID每个进程的运行进度百分比 实验程序设计要求: 1. 命令行参数 参数说明示例值n并发进程数量3total总运行时长(毫秒&…

​​
在这里插入图片描述

一、软件需求

在同时运行多个CPU密集型进程时,需采集以下统计信息:

  • 当前运行在逻辑CPU上的进程ID
  • 每个进程的运行进度百分比

实验程序设计要求:

1. 命令行参数

参数说明示例值
n并发进程数量3
total总运行时长(毫秒)50
resol统计间隔(毫秒)1

2. 进程行为规范

  • 每个进程消耗total毫秒CPU时间后结束
  • resol毫秒记录:
    1. 进程ID(0~n-1)
    2. 累计运行时间(ms)
    3. 进度百分比((i+1)*100/nrecordnrecord=total/resol

二、代码实现

#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <err.h>#define NLOOP_FOR_ESTIMETION 1000000000UL
#define NSEC_PER_SEC    1000000000UL
#define NSEC_PER_MSEC   1000000UL/* 获取纳秒差 */
static inline long diff_nsec(struct timespec before, struct timespec after)
{return ((after.tv_sec * NSEC_PER_SEC + after.tv_nsec) - (before.tv_sec * NSEC_PER_SEC + before.tv_nsec));
}/* 每微秒消耗的空循环的次数 */
static unsigned long loops_per_msec(void)
{struct  timespec before, after;clock_gettime(CLOCK_MONOTONIC, &before);unsigned long i;for(i = 0; i < NLOOP_FOR_ESTIMETION; i++);clock_gettime(CLOCK_MONOTONIC, &after);return ((NLOOP_FOR_ESTIMETION * NSEC_PER_MSEC) / diff_nsec(before, after));
}static inline void load(unsigned long nloops)
{unsigned long i;for(i = 0; i < nloops; i++ );
}static void chidld_fn(int nproc, struct timespec *buf, int nrecord, unsigned long nloop_per_resol, struct timespec start)
{int i;struct timespec ts;for(i = 0; i < nrecord; i++){load(nloop_per_resol);clock_gettime(CLOCK_MONOTONIC, &ts);buf[i] = ts;}printf("nproc\tms\t step\n");printf("---------------------\n");for(i = 0; i < nrecord; i++){printf("%d\t%ld\t%d\n", nproc, diff_nsec(start, buf[i]) / NSEC_PER_MSEC,((i + 1) * 100) / nrecord );}printf("---------------------\n");exit(EXIT_SUCCESS);
}int main(int argc, char *argv[])
{int ret = EXIT_FAILURE;if( 4 > argc){fprintf(stderr, "usage: %s <nproc> <total[ms]> <resolution[ms]>\n", argv[0]);exit(EXIT_FAILURE);}int nproc = atoi(argv[1]); //同时运行的进程的数量int total = atoi(argv[2]); //程序运行的总时长,ms为单位 int resol = atoi(argv[3]); //采集统计信息的间隔if(1 > nproc) //对进程数量参数过滤非法值{fprintf(stderr, "<nproc> (%d) should be >= 1\n", nproc);exit(EXIT_FAILURE);}if(1 > total) //对程序时长参数过滤非法值{fprintf(stderr, "<total> (%d) should be >= 1\n", total);exit(EXIT_FAILURE);}if(1 > resol) //对采集统计信息参数过滤非法值{fprintf(stderr, "<resol> (%d) should be >= 1\n", resol);exit(EXIT_FAILURE);}if(total % resol){fprintf(stderr, "<total> (%d) should be mutliple of <resol> (%d) \n",total, resol);exit(EXIT_FAILURE);}int nrecord = total / resol;struct timespec* logbug = malloc(nrecord * sizeof(struct timespec)); //堆中开辟内存if(!logbug){err(EXIT_FAILURE, "malloc(nrecord) failed");}puts("estimeting workload which just take one millsecond");unsigned long nloops_per_resol = loops_per_msec() * resol;puts("end estimeting");fflush(stdout); // fflush logpid_t* pids = malloc(nrecord * sizeof(pid_t));if(!pids){warn("malloc (pids) failed");goto free_logbuf;}int i, ncreated;struct timespec start;clock_gettime(CLOCK_MONOTONIC, &start);for(i = 0, ncreated = 0; i < nproc; i++, ncreated++){pids[i] = fork();if( 0 > pids[i]){goto wait_children;}else if( 0 == pids[i]){//子进程执行空间chidld_fn(i, logbug, nrecord, nloops_per_resol, start);}}ret = EXIT_SUCCESS;wait_children:if(EXIT_FAILURE == ret) //杀死所有已创建的子进程.{for(i = 0; i < ncreated; i++){if(0 > kill(pids[i], SIGINT)){warn("kill(%d) failed", pids[i]);}}}for(i = 0; i < ncreated; i++) //等待子进程结束{if(0 > wait(NULL)){warn("wait() failed");}}free_pids:free(pids);free_logbuf:free(logbug);exit(ret);
}

三、编译配置(Makefile)

TARGET := app
SRC := sched.c
CPPFLAGS := -pthreadall: $(TARGET)@echo "make successful"$(TARGET): $(SRC)@echo $(SRC)gcc $(CPPFLAGS) $^ -I. -o $@clean:rm $(TARGET)

四、实验结果

nproc   ms      step
---------------------
2       0       2
2       1       4
2       2       6
...
2       172     100
---------------------
nproc   ms      step
---------------------
0       10      2
0       11      4
...
0       176     100
---------------------
nproc   ms      step
---------------------
1       6       2
1       7       4
...
1       203     100
http://www.dtcms.com/wzjs/305851.html

相关文章:

  • 加强网站信息怎么做公关公司是干嘛的
  • 手机网站后台管理系统网站设计制作教程
  • 哈尔滨网站建设贴吧大量微信群推广代发广告
  • jsp做购物网站技术可行性友情链接百科
  • 网站建设网站徒手整形百度高搜
  • 做网站公众号要多少钱广州网络推广万企在线
  • windows 网站建设seo培训机构哪家好
  • 南京市浦口区城乡建设局网站seo的概念
  • wordpress qq快捷登陆深圳优化seo
  • 购物网站开发教程视频浏览器下载安装2023版本
  • 做招聘网站如何宣传百度seo优化技巧
  • 网站做测试怎样做seo是啥意思
  • html5怎么做二手网站磁力搜索引擎
  • 苏州市智信建设职业培训学校网站湖南网站营销推广
  • 网站建设项目报价单厦门百度seo
  • 成品网站 源码1688提高工作效率
  • 做公司网站怎么做手机版新闻发稿平台
  • 深圳网站推广哪家好微信营销软件免费版
  • 我先做个网站怎么做网络营销的作用
  • b2b电子商务平台网站有哪些世界500强企业排名
  • 百度的推广广告长沙百度快速优化排名
  • 如果做淘宝网站项目推广
  • 海口网站建设流程搜多多搜索引擎入口
  • 做网站的人会不会拿走我的网站如何查询网站收录情况
  • 学生处网站建设招标公告杭州网站优化咨询
  • 做原型的素材网站搜索引擎优化技术有哪些
  • 天河区建网站免费自助建站哪个最好
  • 室内设计应该学什么专业六盘水seo
  • 昌吉建设网站网上营销是做什么的
  • 网店网站建设天津做优化好的公司