操作系统实验之Linux下的C程序开发
xxx信息科学技术学院2017计算机专业操作系统及安全实验报告姓名xxx学号xxxxxxx专业班级计算机类x班成绩实验报告题目实验02 Linux下的C程序开发教师评语实验报告内容如下:(适当大小的截图)本次实验以一个简单的C程序为例,请用GCC进行编译并运行。例子由两个文件组成:main.c, calc.c,其中,main.c文件内容为:#include <stdio.h>int calc(int);int main(int argc, char* argv)int iInput=0, iOutput=0;int i=0;scanf("%i",&iInput);while(iInput < 0)printf("Please input a positive integer!n");scanf("%i",&iInput);iOutput = calc(iInput);printf("Result is:%in", iOutput);return 0;calc.c的文件内容为:#include <stdio.h>int calc(int iIn)int i = 0, iOut = 0;iOut = iIn;for(i = 0; i < iIn; i+)iOut += iOut * iIn;return iOut;(一)、用VI编辑器输入以下程序,用gcc编译、运行并截图。程序1:createFork.c#include <stdio.h>#include<unistd.h>#include<sys/types.h>int main( )int p1,p2;while(p1=fork( ) = -1); /*创建子进程p1*/if (p1= =0) putchar(b); else while(p2=fork( ) = = -1); /*创建子进程p2*/if(p2 =0) putchar(c); else putchar(a); return 0;程序 2:anotherFork.c#include <stdio.h>#include<unistd.h>#include<sys/types.h>int main( )int p1,p2,i;while(p1=fork( ) = -1); /*创建子进程p1*/if (p1 =0) for(i=0;i<10;i+)printf("daughter %dn",i);else while(p2=fork( ) = -1); /*创建子进程p2*/if(p2= =0) for(i=0;i<10;i+) printf("son %dn",i);else for(i=0;i<10;i+) printf("parent %dn",i);return 0;(二)、用VI编辑器输入以下程序,用g+编译并运行。程序 1:helloCPP.cpp#include<iostream>using namespace std;int main()cout<<"hello!"<<endl;cout<<"Welcome to c+!"<<endl;return 0;程序 2:isLeapYear.cpp#include <iostream>using namespace std;int main()int year;bool IsLeapYear;cout << "Enter the year: "cin >> year;IsLeapYear = (year % 4 = 0 && year % 100 != 0) | (year % 400 = 0);if (IsLeapYear) cout << year << " is a leap year" << endl;else cout << year << " is not a leap year" << endl;return 0;(三)、完成以下命令:(1) 使用vi编辑器生成三个100行字符,名字分别为my1,my2和my3的文本文件;(2) 在vi编辑my1状态下查看当前编辑文件的文件名、行数以及字符数等信息,使用搜索字符串、删除和粘贴功能,使用替换命令及存盘退出、存盘不退出和不存盘退出命令;(3) 从文件读取输入,并输出到显示器;(4) 把标准输出定向到文件中,记录文件内容;(5) 把my1,my2和my3合并为一个文本文件my,并用命令wc显示其行数、单词数和字符数;(6) 使用管道将my中内容逐屏显示出来;(7) 构造一个”>>”使用符号追加新内容的例子;(8) 查找my ,my1,my2和my3中有没有包含salary,ab、cd的行,有几个文件包含ab。