讲解:C/C++、C/C++、 Operating Systems Programming

CS3103 Operating Systems Programming Assignment 1 Goals By completing this assignment, you should know how to develop a program in Linux platform. and to make system calls related to process management. Introduction You need to implement a C++ program called BP that allows the user to run multiple processes at the background. While processes are running at the background, the user can input command to display information of the background processes, stop, restart or kill a background process. Requirements 1. Your BP needs to show a prompt for user input as follows. cs3103-01:/home/lec/vlee> BP BP > 2. BP accepts the following commands from the user and takes the corresponding action. BP >bg [name of executable file] [a list of arguments] Action: BP runs the executable file with a list of arguments at the background and continues to accept input from the user. Example: BP runs the executable file demo1 with a list of [arguments]: running 2 5 at the background. BP >bg demo1 running 2 5 BP >bglist Action: Display the process id and name of all non-terminated background processes. Example: BP >bglist 16529: demo1 16605: demo2 BP >bgstop [pid] Action: Stop the process with process id pid and display a message. Example: BP >bgstop 16529 16529 stopped BP >bgrestart [pid] Action: Resume the execution of the stopped process with process id pid and display a message. Example: BP >bgrestart 16529 16529 restarted BP >bgstate [pid] Action: Display the process id and state (running, stopped or terminated) of the process with process id pid. Example: BP >bgstate 16529 16529: running CS3103 Operating Systems Programming Assignment 1 BP >bgkill [pid] Action: Terminate the process with process id pid and display a message. Example: BP >bgkill 16529 16529 killed BP >exit Action: BP executes bgkill to terminate all background processes, if any, and exits. Example: BP >exit 16605 killed 16607 killed cs3103-01:/home/lec/vlee> 3. BP should display a message after a background process has completed. Example: 16529 completed 4. BP should display a short and clear message in any other cases such as invalid commands, non-existing process id, no background process, etc. Hints x You may use fork() and execvp() so that the parent process accepts user input and the child process executes the background process. x When you use fork(), it is important that you do not create a fork bomb, which easily eats up all the resources allocated to you. If this happens, you can try to use the command “kill” to terminate your processes (http://cslab.cs.cityu.edu.hk/supports/unix-startup-guide). However, if you cannot log into your account any more, you need to ask CSLab for help to kill your processes代写C/C++编程、C/C++课程设计代写、 Operating Systems Programming 实验代做. x You may use waitpid() with an option WNOHANG to check if a background process has completed. x You may use the kill() system call to send a signal to a process, e.g., a SIGTERM signal to terminate a process. x You should study the man pages of the system calls before calling them in your program. For example, the following command displays the man pages of kill() in Section 2. cs3103-01:/home/lec/vlee> man 2 kill Helper programs demo.cpp x This demo program can be used to act as a background process for testing your BP as its execution can be visualized by displaying a word every few seconds a number of times. x This program takes three arguments, word, interval and times. x The first argument word is a single word to be displayed repeatedly. x The second argument interval is the number of seconds between two consecutive displays of the word. x The third optional argument times is the number of times the word to be displayed. If this argument is missing, the word will be displayed infinite number of times. CAUTION: DROPPING THIS ARGUMENT MAY CAUSE A FORK BOMB. x For example, the following command displays the word “running” 5 times in 2-second interval. cs3103-01:/home/lec/vlee> demo running 2 5 CS3103 Operating Systems Programming Assignment 1 args.cpp x This example program shows how to display a list of all arguments passed to it. x To compile the program, use the following command. cs3103-01:/home/lec/vlee> g++ args.cpp -lreadline -lhistory -o args Marking x You program will be tested on our CSLab Linux servers (cs3103-01, cs3103-02, cs3103-03). If an executable file cannot be generated and running successfully on our Linux servers, it will be considered as unsuccessful. x Marking scheme (total: 100%): o bg 20% o bglist 10% o bgstop 10% o bgrestart 10% o bgstate 10% o bgkill 10% o exit 10% o Handling of other cases 10% o programming style. and in-program comments 10% Submission x This assignment has to be done individually or by a group of two students. You are encouraged to discuss the high-level design of your solution with your classmates but you must implement the program on your own. Academic dishonesty such as copying another student’s work or allowing another student to copy your work, is regarded as a serious academic offence. x Each submission consists of two files: a source program file (.cpp file) and a text file containing all possible outputs produced by your program (.txt file). x Use your student ID(s) to name your submitted files, such as 5xxxxxxx.cpp, 5xxxxxxx.txt for individual submission, or 5xxxxxxx_5yyyyyyy.cpp, 5xxxxxxx_5yyyyyyyy.txt for group submission. Only ONE submission is required for each group. x Submit the files to Canvas. x The deadline is 10:00 a.m., 23-FEB-18 (Friday). No late submission will be accepted. Questions? x Contact Miss LIANG, Yu at or your course lecturer. & 转自:http://ass.3daixie.com/2018052158548704.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,100评论 6 493
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,308评论 3 388
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 159,718评论 0 349
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,275评论 1 287
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,376评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,454评论 1 292
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,464评论 3 412
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,248评论 0 269
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,686评论 1 306
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,974评论 2 328
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,150评论 1 342
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,817评论 4 337
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,484评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,140评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,374评论 1 267
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,012评论 2 365
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,041评论 2 351

推荐阅读更多精彩内容