CSCI 3100 Unix and C

Your name:
S number: Homework 3
CSCI 3100 Unix and C
November 4, 2019
1 Process and thread handling.
How to submit?
(a) Zip your source codes and a screenshot (cellphone pictures are OK) for each programming
problem. Make sure to name your file in the format of ”problem1.c” and ”screenshot1.jpg”.
(b) Submit the zip file to Blackboard.
Forking is very useful for applications with multiple simultaneous connections. For example,
modern internet browser like Google Chrome, it creates processes for independent websites,
plugins, etc. In this assignment, you will write a program to simulate how it works.
1.1 Create a program for internet browser simulation. Requirement:
1. It has a loop to receive user’s input.
2. User can either input an URL of a website, a PID or message “exit”.
3. If the input is an URL, use the fork function to create another process.
(a) fork();
(b) For parent process, prints a message “Create a process PID for new website”.
Replace PID to the PID that you get from the fork() function.
(c) For child process, prints a message “You are visiting website URL”. Replace URL
CSCI 3100作业代做、C++程序语言作业调试
to the actual URL you pass to the child process.
(d) For the child process, after printing that message, create an infinite loop to prevent
the child process from exiting until it receives a signal from the parent asking it
to exit.
4. If the input is a PID, send a SIGQUIT signal to the child process and ask it to quit.
You can use the following function to check if the input can be converted to integer:
1 i n t isNumber ( ch a r s [ ] , i n t s i z e )
2 {
3 f o r ( i n t i = 0 ; i < s i z e ; i++)
4 i f ( i s d i g i t ( s [ i ] ) == f a l s e )
5 r e t u r n 0 ;
6
7 r e t u r n 1 ;
8 }
9
1
Your name:
S number: Homework 3
CSCI 3100 Unix and C
November 4, 2019
If the function return 1, then use function atoi() to convert it into integer.
5. If the input is “exit”, quit your program.
Here is an example output:
Figure 1: Sample output
1.2 Create a thread of function “mythread()” in your program
and wait until it finishes. Requirements:
1. Before creating the thread, print a message “A thread is going to be created.” in the
main thread.
2. In the function “mythread()”, print messages “Counting...” 10 times.
3. After executing the thread, print message “Done executing thread.” in the main thread.
1.3 Bonus 20 pts. If you can submit Makefile to compile the problems
above with “make”, you will get 10 pts for each problem.
2

因为专业,所以值得信赖。如有需要,请加QQ:99515681 或 微信:codehelp

原文地址:https://www.cnblogs.com/simplebluejava/p/11978674.html

时间: 2024-08-30 18:03:09

CSCI 3100 Unix and C的相关文章

CSCI 2132: Software Development

Assignment 6CSCI 2132: Software DevelopmentDue April 1, 2019Assignments are due on the due date before 23:59. All assignments must be submitted electronically via the course SVNserver. Plagiarism in assignment answers will not be tolerated. By submit

Unix 环境高级编程 (APUE) 之 网络 IPC:套接字

一起学 Unix 环境高级编程 (APUE) 之 网络 IPC:套接字 . . . . . 目录 (一) 一起学 Unix 环境高级编程 (APUE) 之 标准IO (二) 一起学 Unix 环境高级编程 (APUE) 之 文件 IO (三) 一起学 Unix 环境高级编程 (APUE) 之 文件和目录 (四) 一起学 Unix 环境高级编程 (APUE) 之 系统数据文件和信息 (五) 一起学 Unix 环境高级编程 (APUE) 之 进程环境 (六) 一起学 Unix 环境高级编程 (APU

一个基于Unix套接字的注册登录系统

2016/5/5 今天,我参考<Unix网络编程-卷1>第5章的TCP回射客户/服务器程序写了一个简单的注册登录系统,其功能如下:(1)注册.客户端向服务器发送个人信息请求注册,服务器查询MySQL数据库以检查该客户是否已存在,若是则禁止注册,并返回“用户已存在,注册失败”的错误信息,否则将新用户信息添加到MySQL数据库,并返回“注册成功”的信息.(2)登录.客户端向服务器发送个人账号和密码等两项信息,服务器查询MySQL数据库以检查账号是否存在.账号和密码是否匹配,若不存在或不匹配则禁止登

php日期和时间基础知识--Unix时间戳

<?php /*1.取得当前的Unix时间戳 UNIX 时间戳(英文叫做:timestamp)是 PHP 中关于时间与日期的一个很重要的概念,它表示从 1970年1月1日 00:00:00 到当前时间的秒数之和. PHP提供了内置函数 time() 来取得服务器当前时间的时间戳.那么获取当前的UNIX时间戳就很简单了. */ $timer = time(); echo $timer; /*2.取得当前的日期 php内置了date()函数,来取得当前的日期. 函数说明:date(时间戳的格式, 规

六、Linux/UNIX操作命令积累【kill、netstat、df、du】

在使用Linux/UNIX下,经常会使用文本界面去设置系统或操作系统,作者本人在工作的过程也在不断接触这方面的命令,所以为此特酝酿.准备.开始了本文的编写.本文主要记录自己平时遇到的一些Linux/UNIX下操作命令,记录与整理一下,一可加深印象,二可记录分享.希望各位看官,对于不合适的或有歧义的地方,给予指明与说明,以便共同学习与提高. [转载使用,请注明出处:http://blog.csdn.net/mahoking] 023 kill命令:查看进程及杀死进程 查看进程使用ps命令,本例演示

unix 文件属性

在unix下提到文件属性,不得不提的一个结构就是stat,stat结构一般定义如下: struct stat { dev_t st_dev; /* ID of device containing file */ ino_t st_ino; /* inode number */ mode_t st_mode; /* protection */ nlink_t st_nlink; /* number of hard links */ uid_t st_uid; /* user ID of owner

Linux - Unix环境高级编程(第三版) 代码编译

Unix环境高级编程(第三版) 代码编译 本文地址:http://blog.csdn.net/caroline_wendy 时间:2014.10.2 1. 下载代码:http://www.apuebook.com/code3e.html 2. 安装依赖库:sudo apt-get install libbsd-dev  3. 进入下载目录make 4. 复制头文件和动态链接库 sudo cp ./include/apue.h /usr/include/ sudo cp ./lib/libapue

UNIX环境编程学习笔记(6)——文件I/O之判断文件类型

lienhua342014-09-01 1 文件类型 我们平时最常接触的文件类型有普通文件(regular file)和目录(di-rectory file),但是 UNIX 系统提供了多种文件类型: (1) 普通文件(regular file) 这种文件包含了某种形式的数据,这些数据无论是文件还是二进制对于 UNIX 内核而言都是一样的.对普通文件内容的解释有处理该文件的应用程序进行. (2) 目录文件(directory file) 目录文件包含了其他文件的名字以及指向与这些文件有关信息的指

UNIX环境编程学习笔记(4)——文件I/O之dup复制文件描述符

lienhua342014-08-23 UNIX 提供了两个函数 dup 和 dup2 用于复制一个现存的文件描述符. #include <unistd.h> int dup(int filedes); int dup2(int filedes, int filedes2); 返回值:若成功则返回新的文件描述符,如出错则返回-1. 由 dup 函数返回的文件描述符一定是当前可用文件描述符中的最小描述符.用 dup2 函数则可以通过参数 filedes2 指定目标文件描述符.如果filedes2