CS3214 Fall 2024 Project 1 - “Customizable Shell”R

本文为博客 VIP 文章,开通 VIP 后可阅读全文

开通 VIP

Java Python CS3214 Fall 2024

Project 1 - “Customizable Shell”

Due Date: See website for due date (Late days may be used.)

This project must be done in groups of 2 students. Self-selected groups must have regis-tered using the grouper app (URL). Otherwise, a partner will be assigned to you.

1 Introduction

This assignment introduces you to the principles of process management and job control in a Unix-like operating system. In this project, you will develop a simple job control shell.

This is an open-ended assignment. In addition to implementing the required functional-ity, we encourage you to define the scope of this project yourself.

2 Base Functionality

A shell receives line-by-line input from a terminal that represents user commands. Some user commands are builtins, which are implemented by the shell itself. If the user inputs the name of such a built-in command, the shell will execute this command. Otherwise, the shell will interpret the input as containing the name of an external program to be executed, along with arguments that should be passed to it. In this case, the shell will fork a new child process and execute the program in the context of the child. Normally, the shell will wait for a command to complete before reading the next command from the user. However, if the user appends an ampersand ‘&’ to a command, the command is started and the shell will return to the prompt immediately. In this case, we refer to the running command as a “background job,” whereas commands the shell waits for before processing new input are called “foreground jobs.”

The shell provides job control. A user may interrupt foreground jobs, send foreground jobs into the background, and vice versa. Thus at a given point in time, a shell may run zero or more background jobs and zero or one foreground jobs. If there is a foreground job, the shell waits for it to complete before printing another prompt and reading the next command. In addition, the shell informs the user about status changes of the jobs it manages. For instance, jobs may exit, or terminate due to a signal, or be stopped for several reasons.

At a minimum, we expect that your shell has the ability to start foreground and back-ground jobs and implements the built-in commands ‘jobs,’ ‘fg,’ ‘bg,’ ‘kill,’ ’exit,’ and ‘stop.’ The semantics of these commands should match the semantics of the same-named commands in bash. The ability to correctly respond to ˆC (SIGINT) and ˆZ (SIGTSTP) is expected, as are informative messages about the status of the children managed. Like bash, you should use consecutively numbered small integers to enumerate your jobs.

For the minimum functionality, the shell need not support pipes (|), I/O redirection (< > >>), nor the ability to run programs that require exclusive access to the terminal (e.g., vim).

We expect most students to implement pipes, I/O redirection, and managing the con-trolling terminal to ensure that jobs that require exclusive access to the terminal obtain such access (see Section 3.3). Beyond that, cush’s customizability, described in Section 5, should allow for plenty of creative freedom.

3 Strategy

3.1 Handling SIGCHLD To Process Status Changes

At a given point in time, a user may have multiple jobs running, each executing arbitrary programs chosen by the user. Because the shell cannot and does not know what these programs do, it has to rely on a notification facility from the OS to be informed when these jobs encounter events the shell needs to know about. We refer to such events as “changing status,” where “status” means whether the job is running, has been stopped, has exited, or has been terminated with a signal (for instance, crashed).

This notification facility involves a protocol in which the OS kernel sends an asynchronous signal (SIGCHLD) to the shell, and in which the shell then follows up by executing a sys-tem call (a variant of wait(), specifically waitpid(), as shown in the provided starter code).

Thus, you will need to catch the SIGCHLD signal to learn about when the shell’s child processes change status. Since child processes execute concurrently with respect to the parent shell, and since the shell has no knowledge of what these processes are doing, it is impossible to predict when a child will exit (or terminate with a signal), and thus it is impossible to predict when this signal will arrive. In the worst case, a child may have already terminated by the time the parent returns from fork()! You also should not make any assumptions about how a child process might change state: for instance, even if the user issues a kill built-in command to terminate a process, the processes might not immediately terminate (or may not terminate at all), so the shell should not assume that a status change occurred unless and until it has first-hand information from the OS that it did.

Because of the asynchronous nature of signal delivery, you will need to block handling of the signal in those sections of your code where you access data structures that are also needed by the handler that is executed when this signal arrives. For example, consider the data structure used to maintain the current set of jobs. A new job is added after a child process has been forked; a job may need to be removed when SIGCHLD is received. To avoid a situation where the job has not yet been added when SIGCHLD arrives, or - worse - a situation in which SIGCHLD arrives while the shell is adding the job, the parent should block SIGCHLD until after it completed adding the job to the list. If the SIGCHLD signal is delivered to the shell while the shell blocks this signal, it is marked pending and will be received as soon as the shell unblocks this signal.

Use the provided helper functions in signal support.c to block and unblock sig-nals, which in turn rely on sigprocmask(2). To set up signal handlers, they use the sigaction(2) system call with sa flags set to SA RESTART. The mask of blocked signals is inherited when fork() is called. Consequently, the child will need to unblock any signals the parent had blocked before calling exec().

3.2 Process Groups

User jobs may involve multiple processes. For instance, the command line input ls | grep filename requires that the shell start two processes, one to execute the ls and the other to execute the grep command. Aside from this example, child processes that a user program may start should usually be part of the same job so that the user can manage them as one unit. To help manage these scenarios, Unix introduced a way to group processes that makes it simpler for the shell and for the user to address them as one unit.

Each process in Unix is part of a group. Process groups are treated as an ensemble for the purpose of signal delivery and when waiting for processes. Specifically, the kill(2), killpg(2), and waitpid(2) system calls support the naming of process groups as possible targets. In this way, if a user wants

在 SAP BTP ABAP 环境中测试多租户 SaaS 解决方案的完整实践指南 ABAP SaaS测试阶段关键实践 在SAP BTP ABAP环境中开发多租户SaaS解决方案时,测试阶段(TST)对确保产品质量尤为关键。测试阶段应包含两个主要维度: 业务功能验证: 通过软件组件管理确保测试环境与代码仓库同步 创建并验证业务角色分配,确保权限配置正确 测试Fiori Launchpad导航流程和跨应用跳转 验证inbound/outbound通信配置 自动化质量管控: 在开发环境(DEV)执行本地ATC检查和单元测试 通过ABAP Test Cockpit(ATC)进行代码质量检查 集成 阅读详情

相关推荐

基于Python+OpenPose(带GUI界面)的太极拳姿态识别系统+源代码+文档说明+数据集(多种姿势)+模型(高分毕设)

<项目介绍>基于Python+OpenPose(带GUI界面)的太极拳姿态识别系统+源代码+文档说明+数据集(多种姿势)+模型std.txt为标准姿态数据,ProcessImage.py用来获取图片姿态数据,Classifier.py用来实现姿态分类,GUI2-3.py为GUI界面代码-不懂运行,下载完可以私聊问,可远程教学该资源内项目源码是个人的毕设,代码都测试ok,都是运行成功后才上传资源,答辩评审平均分达到96分,放心下载使用!1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!2、本项目适合计算机相关专业(如计科、人工智能、通信工程、自动化、电子信息等)的在校学生、老师或者企业员工下载学习,也适合小白学习进阶,当然也可作为毕设项目、课程设计、作业、项目初期立项演示等。3、如果基础还行,也可在此代码基础上进行修改,以实现其他功能,也可用于毕设、课设、作业等。下载后请首先打开README.md文件(如有),仅供学习参考, 切勿用于商业用途。----------------------------------------------

解决地线设计问题导致TMS320 DSP JTAG无法连接,报错Error -516 @ 0x0 failed the scan-path reliability test

芯片为TMS320F28035,新投的PCB,送焊回来后连接JTAG仿真器发现连接不上,报错如下:Error connecting to the target: (Error -516 @ 0x0) The user selected specific frequency failed the scan-path reliability test. The utility or debugger ...

BlairFee的博客 6221

JTAG接口无法连接的问题

本文包含两部分内容:1)续写TI DSP连接不上的问题;2)顺便提一下Xilinx FPGA的JTAG口连接不上的问题。

Linux内核配置(4)

(X) Flat Memory 平面内存 ( ) Sparse Memory 稀疏内存 提供内存热拔插支持。 [ ] Allow for memory compaction (NEW) -*- Page migration [ ] Enable KSM for page merging (NEW) 与KVM虚拟机有关的内存管理技术。可选N (4096) Low address space

浪迹一生 4674

DSP仿真器Debug错误原因及解决办法

错误现象:在使用xds100v3仿真器调试tms320c6747处理器时,出现如下一堆错误。C674X_0: Power Failure on Target CPU Error connecting to the target:(Error -1265 @ 0x0)Device ID is not recognized or is not supported by driver. Confirm ...

无语僧 3万+

Schrodinger Suite 2026.3高级版_Win/Mac/Linux_新版更新了啥?

Schrödinger Suite 2026是领先的计算化学与分子模拟软件,涵盖小分子药物发现、生物制剂开发、材料科学等领域的完整解决方案。2026.3版新增RBSS快速结合位点搜索、晶体结构预测、大环对接提速2.5倍等重磅功能。了解系统要求、行业应用与版本更新详情。

badboy121的博客 438

Linux】 阶段性复习(linux vim gcc makefile gdb)

Linux命令与工具速查摘要 本文整理了Linux常用命令和开发工具的核心用法,分为以下四部分: 1. Linux常用命令分类 目录导航:pwd/ls/cd/mkdir/rmdir 文件操作:touch/rm/cp/mv 内容查看:cat/more/less/head/tail 搜索查找:find/grep/which/whereis 压缩传输:zip/unzip/rz/sz/tar 系统信息:date/cal/bc/uname 帮助与热键:man/alias/Tab补全/Ctrl+c终止 2. Vim核心

专注后端与底层技术,分享实战干货与学习笔记,梦想进入字节跳动,步履不停,热爱不止。 778

Linux编程-进程的执行和退出

fork()会;单纯 fork 出来的子进程,代码、数据和父进程完全相同,只能执行父进程现存代码。exec。

2401_82879595的博客 215

Linux首战之进度条

有句标题很好——实践是检验真理的唯一标准,手上有了vim,gcc/g++和make/makefile工具以后,让我们利用它们来完成首个linux项目——进度条。

2401_87941709的博客 229

Linux|运维|docker+centos7部署最新版seafile私有网盘社区版-2026(可离线部署)

Seafile是一款由海文互知开发的私有云存储平台,支持文件同步、共享和跨平台访问。本文详细介绍了Seafile社区版在CentOS 7系统下的Docker容器化部署流程: 环境准备:要求Docker 20.10.10+版本,升级libseccomp至2.5.2,安装docker-compose插件; 部署步骤:下载编排文件(seafile-server.yml/seadoc.yml/.env),配置端口(示例使用10086)、数据库密码等参数; 特别处理:修改Nginx配置以支持SeaDoc文档协作功能,

zsk_john的技术分享专用博客 280

Linux】多路转接epoll

本期博客讲解了使用epoll实现多路转接/多路复用技术,讲解了epoll的工作流程,并使用epoll实现了一个简单的Echo Server服务器,最后讲解了epoll的两种工作模式LT、ET。

2401_86785052的博客 654

Linux 资源控制实战分析:用 LXC 亲手造一个 “迷你虚拟机“

本文是一篇面向Linux新手的LXC容器实战教程,通过通俗易懂的比喻讲解容器技术核心概念,并提供详细操作指南: 核心概念 用"房子装修"比喻解释容器与虚拟机的区别:容器是轻量级隔离(轻质隔板),共享内核资源 揭示Linux容器的两大技术支柱:Namespace(隔离视角)和Cgroups(资源限制) 实战步骤 环境准备:Ubuntu/CentOS系统安装LXC工具套件 创建容器:使用模板快速部署Ubuntu容器(lxchost1) 生命周期管理:启动/停止/删除容器完整流程 容器体验:通

m0_66687213的博客 163

OpenAI Linux 版来了!

不过这次是 Preview 版本,有些功能还没实现,比如官方社媒提到了浏览器工作流,帮助中心对内置浏览器和 Voice 的说明仍然只写了 macOS 和 Windows。于是今天,你现在可以在 Mac、Windows 和 Linux 上都能使用 ChatGPT 了,OpenAI 这是想要一统桌面端吗?就在今天早上,OpenAI 官宣了这条消息,你在 Linux 上,也能使用 ChatGPT 了!虽然 ChatGPT 已在世界各地的桌面端普及了,但此前一直缺席一个重要的场景,Linux

程序员cxuan的个人主页 198

Arch Linux 无显示器服务器 SSH 远程麦克风监听与取证录音实战

摘要:在ArchLinux服务器上远程使用SSH时,插入麦克风后声卡设备消失。排查发现核心原因是用户不在audio组,且SSH无图形会话导致PipeWire无权访问/dev/snd/*设备。解决方案包括: 权限修复:将用户加入audio组,并通过udev规则调整设备权限; 服务配置:重启WirePlumber和PipeWire服务,确保无图形环境下的音频设备枚举; 单声道处理:通过PipeWire的loopback模块创建虚拟单声道源; 无损录音与监听:使用ffmpeg抓取原始PCM流,结合WebAudio

2601_96158891的博客 395

Linux】ELF与库加载

c源代码经过预处理,再经过编译生成汇编.s,最后汇编生成可重定位目标文件.o.o,不能直接运行,必须经过链接器链接。

2501_93806388的博客 315

Linux 清理踩坑记录:一个包删掉了整个桌面

Linux软件删除的血泪教训:新手因不了解依赖关系链,多次误删关键组件(如KDE桌面、Firefox等)。核心问题是Linux的硬依赖(Depends)会级联删除上层软件,与Windows逻辑完全不同。安全操作守则:1)先用--dry-run模拟删除;2)用apt-cache depends检查依赖类型;3)确保待删列表中无关键软件。仅Recommends/Suggests层级的包可安全删除。重要经验:不确定的包不要动,依赖树比表面看起来复杂得多。

qq_36710118的博客 370

嵌入式 Linux 系统移植与 SD 卡量产镜像制作

本文详细介绍了将嵌入式Linux系统(Uboot+内核+设备树+根文件系统)打包成SD卡镜像的完整流程。主要内容包括:1. 系统启动流程解析:从上电到内核加载的全过程;2. 五步实现方案:存储分区规划(FAT+EXT4)、Uboot自动启动配置、源码修改编译、镜像打包(使用dd工具)和烧录验证;3. 关键实现细节:Uboot环境变量设置、分区布局设计(50MB FAT+150MB EXT4)、自动化脚本添加等。最终生成的.img文件可直接用于工厂批量烧录,实现设备上电即用功能。

XINGXIN 225

linux笔记归纳15:自定义协议与序列化

目录自定义协议与序列化一、应用层1.1.应用层协议1.2.序列化和反序列化1.3.重新理解read和write二、Jsoncpp2.1.Jsoncpp概念2.2.Jsoncpp安装2.3.序列化2.4.反序列化2.5.手写序列化和反序列化三、进程间关系与守护进程3.1.进程组3.2.组长进程3.3.会话3.4.任务3.5.控制终端3.6.作业控制3.7.守护进程3.8.setsid函数3.9.null文件3.10.daemon函数四、网络版计算器2.1.socket封装2.2.自定义协议2.3.设计服务器

yonakaame的博客 268

Linux 基础与 Shell 命令

今天是第24天,前面一直在写 C 语言和数据结构,今天转回 Linux 系统编程基础。Linux 是嵌入式 C 开发的主战场,内核、shell、常用命令、简单 shell 脚本,都是日常写代码、调试、编译必不可少的基本功。shell 脚本语法对空格极其敏感,if[]条件前后必须留空格。脚本写完一定要加执行权限chmod +x,否则不能./运行。重定向和>>不要搞混,会直接清空原有文件。rm -rf谨慎使用,没有回收站,删除无法恢复。

weixin_48445537的博客 618

Linux】Xshell 8免费版下载安装注册连接(初学者学习Linux的工具)

本文详细介绍了Xshell 8的下载、安装、注册及连接Linux服务器的完整流程。提供官网和百度网盘(提取码2586)两种下载方式,分步骤图解说明安装过程(包括协议同意、安装位置选择等)。注册环节需通过邮箱验证,连接Linux服务器时需要输入公网IP和账户密码。全文通过10张配图直观展示每个操作环节,最终以命令行提示符验证连接成功,适合新手快速完成Xshell 8的部署和使用。

2301_82161965的博客 265

Linux】网络编程 —— 传输层协议 TCP(下)

但行好事,莫问前程

qq_42996461的博客 276
上一篇: MINERALOGY TASK#:1Web
下一篇: Budget Holiday IR
ishytynt
博客等级 码龄2年 362粉丝 · 43原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值