最近做了操作系统的实验,进程控制,踩了不少坑。现在总结下。
Liunx:先放代码
#include<iostream>
#include<cstdlib> //sleep()
#include<unistd.h> //fork
#include<sys/time.h> //gettimeofday
#include<sys/wait.h> //wait
#include<ctime> //localtime
void outputTime(struct tm*time,int ms);
using namespace std;
int main(int argc,char*argv[])
{
struct timeval startTime;
struct timeval endTime;
struct timezone zone;
time_t startTime_t;
time_t endTime_t;
struct tm *startTime_tm;
struct tm *endTime_tm;
int pid=fork();
if(pid<0){
cout<<"error"<<endl;
exit(0);
}
if(pid==