Operating System question

    When a UNIX-like system starts up, it runs init. Nowadays this is a program called systemd on UNIX-like systems. On Mac the similar system manager is called launchd. It runs under PID of 1 and is an ancestor of all other processes. You can see the process with command “ps aux”. If a process is left as an orphan (its parent dies), it gets reassigned as a child of PID 1. These service programs (init, systemd or launchd) are running in the background; on UNIX-like OSs these are commonly referred to as daemons and generally have names ending with the letter “d.” These programs ensure that things start up properly and stay running.  If a process crashes systemd (or launchd) can detect this and start it back up.
   You will develop a proc_manager program that reads in the commands to execute from an input file one-by-one. You will read one command and its parameters per each line. Then the proc_manager program will start up the process and “babysit” it.You will run each command in a child process using exec (or one of its variants) and the parent process will wait for each exec to complete. For each child process there will be log messages written to output and error files, which are named after its index in the sequence of commands read in. For example, process #1 will have logs written to 1.out and 1.err. Upon start, the string “Starting command INDEX: child PID pid of parent PPID” will be logged to the corresponding output file 1.out. You can retrieve PID and PPID through the return value of fork() or getpid() or getppid().You can use dup2() to make file handle 1 (stdout) go to a file X.out and handle 2 (stderr) go to a file X.err. Note: new executions of a command should append to the previous output and error files, such as 1.out, rather than overwrite them.
   Timer for each process: you can include the timer.h library and use timer to record the start time of spawning each child process in the parent. Upon finish of an exec (either a successful finish or termination via a signal), the process should record the finish runtime, and it should write to the output file the string “Finished at FIN, runtime duration DUR” where FIN is the finish time and DUR is the duration of the execution.
   Each time a process finishes, the message “Exited with exitcode = X” should be written to the error file of the process. X is the process exit code. If the process was killed with a signal, then “Killed with signal S” should be written to the error file. S is the signal number that killed the process. This information is gathered using the status parameter of the wait() system call. If the program cannot be started (exec fails), use perror(“name of command“) to get the error message and command name and write them to the command’s error file. Processes that encounter an invalid command (exec fails) should have an exit code of 2. Remember the exit code of 0 indicates success. Exit codes other than 0 indicate some failure, including a termination via a kill signal.Here is an example run:

./proc_manager

Don't use plagiarized sources. Get Your Custom Essay on
Operating System question
Just from $13/Page
Order Essay

cmdfile

Where cmdfile contains:

prompt> cat cmdfile
sleep 5
ls -latr
pwd
sleep 1
wc /etc/passwd

    The parent will re-start the executable if the command took more than two seconds to complete. Therefore, a process restarts as long as its last execution took more than 2 seconds. If a process completed within less than 2 seconds after starting, proc_manager will not restart it and will print a message “spawning too fast” to the error file for the process. If it was terminated by a signal right after it started, or it had some other failure that caused it to exit immediately, it won’t restart, since it exited immediately.
   proc_manager runs until there are no more processes running. In this example the ls and wc commands won’t get restarted because they finish right after they are started. The sleep runs for 3 seconds, so proc_manager will keep restarting it, unless we do “pkill sleep” in another terminal. If we do pkill fast enough, proc_manager will detect the quick duration and exit and not restart it. If any process has no child process then wait() returns immediately “-1”, thus you can continue until wait() returns -1.

Grading

code compiles without errors or warnings -Wall on VirtualBox10%

correctly uses fork()10%

correctly uses wait*()10%

correctly uses dup2()10%

a version of exec is used correctly10%

the exit and signal codes and spawning messages are printed correctly10%

all processes run in parallel10%

an output and error file is created for each command10%

code is commented and indented (use of white space)10%

zip file contains proc_manager.c10%

Submission

    Upload a zip file called proj3.zip that contains your source files that are needed to compile and run on VirtualBox (including proc_manager.c).

/**
*CommandNode.c
*Author: Bill Andreopoulos
*The function bodies for a linked list of commands
*CS149 assignment 3 usage only
**/
/**
Example of linked list initialization in code:
//First command node (head of list)
headCommand = (CommandNode*)malloc(sizeof(CommandNode));
CreateCommandNode(headCommand, command, index, NULL);
…..
//Later command nodes
nextCommand1 = (CommandNode*)malloc(sizeof(CommandNode));
CreateCommandNode(nextCommand1, command, index, NULL);
InsertCommandAfter(headCommand, nextCommand1);
**/
//create a new command node. usually nextCmd can be NULL and function InsertCommandAfter can be called to insert after head node.
void CreateCommandNode(CommandNode* thisNode, char cmd[20][20], int ind, CommandNode* nextCmd) {
//this is useful if you store a string (char *): strcpy(thisNode->command, cmd);
for (int i = 0; i < 20; i++) for (int j = 0; j < 20; j++) thisNode->command[i][j] = cmd[i][j];
thisNode->index = ind;
thisNode->nextCommandPtr = nextCmd;
return;
}
//insert node newNode after thisNode
void InsertCommandAfter(CommandNode* thisNode, CommandNode* newNode) {
CommandNode* tmpNext = NULL;

tmpNext = thisNode->nextCommandPtr;
thisNode->nextCommandPtr = newNode;
newNode->nextCommandPtr = tmpNext;
return;
}
//get next command node in linked list
CommandNode* GetNextCommand(CommandNode* thisNode) {
return thisNode->nextCommandPtr;
}
//find a command based on the pid
CommandNode* FindCommand(CommandNode* cmd, int pid) {
CommandNode* tmpNext = cmd;
while (tmpNext != null) {
if (tmpNext->PID == pid) { return tmpNext; }
tmpNext = tmpNext->nextCommandPtr;
}
return NULL;
}

sleep 5
ls -latr
sleep 3
pwd
sleep 1
wc /etc/passwd

/**
*CommandNode.h
*Author: Bill Andreopoulos
*The struct for a Command Node and function prototypes for a linked list of commands
*CS149 assignment 3 usage only
**/

typedef struct command_struct {
char command[20][20];
int index;
int PID;
int starttime;
bool active;
struct command_struct* nextCommandPtr;
} CommandNode;

void CreateCommandNode(CommandNode* thisNode, char cmd[20][20], int ind, CommandNode* nextCmd);
void InsertCommandAfter(CommandNode* thisNode, CommandNode* newNode);
CommandNode* GetNextCommand(CommandNode* thisNode);
CommandNode* FindCommand(CommandNode* cmd, int pid);

/* Program to demonstrate time taken by function fun() */
#include
#include

// A function that terminates when enter key is pressed
void fun()
{
printf(“fun() starts \n”);
printf(“Press enter to stop fun \n”);
while(1)
{
if (getchar())
break;
}
printf(“fun() ends \n”);
}

// The main program calls fun() and measures time taken by fun()
int main()
{
// Calculate the time taken by fun()
struct timespec start, finish;
double elapsed;
clock_t t;
t = clock();
clock_gettime(CLOCK_MONOTONIC, &start);
printf(“start %ld\n”, start.tv_sec);
fun();
clock_gettime(CLOCK_MONOTONIC, &finish);
printf(“finish %ld\n”, finish.tv_sec);
//printf(“CLOCKSPERSEC %ld\n”, CLOCKS_PER_SEC);
//double time_taken = ((double)t)*1000.0/CLOCKS_PER_SEC; // in seconds
elapsed = (finish.tv_sec – start.tv_sec);
//Alternative with more precision:
//elapsed += (finish.tv_nsec – start.tv_nsec) / 1000000000.0;

printf(“fun() took %f seconds to execute \n”, elapsed);
return 0;
}

What Will You Get?

We provide professional writing services to help you score straight A’s by submitting custom written assignments that mirror your guidelines.

Premium Quality

Get result-oriented writing and never worry about grades anymore. We follow the highest quality standards to make sure that you get perfect assignments.

Experienced Writers

Our writers have experience in dealing with papers of every educational level. You can surely rely on the expertise of our qualified professionals.

On-Time Delivery

Your deadline is our threshold for success and we take it very seriously. We make sure you receive your papers before your predefined time.

24/7 Customer Support

Someone from our customer support team is always here to respond to your questions. So, hit us up if you have got any ambiguity or concern.

Complete Confidentiality

Sit back and relax while we help you out with writing your papers. We have an ultimate policy for keeping your personal and order-related details a secret.

Authentic Sources

We assure you that your document will be thoroughly checked for plagiarism and grammatical errors as we use highly authentic and licit sources.

Moneyback Guarantee

Still reluctant about placing an order? Our 100% Moneyback Guarantee backs you up on rare occasions where you aren’t satisfied with the writing.

Order Tracking

You don’t have to wait for an update for hours; you can track the progress of your order any time you want. We share the status after each step.

image

Areas of Expertise

Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.

Areas of Expertise

Although you can leverage our expertise for any writing task, we have a knack for creating flawless papers for the following document types.

image

Trusted Partner of 9650+ Students for Writing

From brainstorming your paper's outline to perfecting its grammar, we perform every step carefully to make your paper worthy of A grade.

Preferred Writer

Hire your preferred writer anytime. Simply specify if you want your preferred expert to write your paper and we’ll make that happen.

Grammar Check Report

Get an elaborate and authentic grammar check report with your work to have the grammar goodness sealed in your document.

One Page Summary

You can purchase this feature if you want our writers to sum up your paper in the form of a concise and well-articulated summary.

Plagiarism Report

You don’t have to worry about plagiarism anymore. Get a plagiarism report to certify the uniqueness of your work.

Free Features $66FREE

  • Most Qualified Writer $10FREE
  • Plagiarism Scan Report $10FREE
  • Unlimited Revisions $08FREE
  • Paper Formatting $05FREE
  • Cover Page $05FREE
  • Referencing & Bibliography $10FREE
  • Dedicated User Area $08FREE
  • 24/7 Order Tracking $05FREE
  • Periodic Email Alerts $05FREE
image

Our Services

Join us for the best experience while seeking writing assistance in your college life. A good grade is all you need to boost up your academic excellence and we are all about it.

  • On-time Delivery
  • 24/7 Order Tracking
  • Access to Authentic Sources
Academic Writing

We create perfect papers according to the guidelines.

Professional Editing

We seamlessly edit out errors from your papers.

Thorough Proofreading

We thoroughly read your final draft to identify errors.

image

Delegate Your Challenging Writing Tasks to Experienced Professionals

Work with ultimate peace of mind because we ensure that your academic work is our responsibility and your grades are a top concern for us!

Check Out Our Sample Work

Dedication. Quality. Commitment. Punctuality

Categories
All samples
Essay (any type)
Essay (any type)
The Value of a Nursing Degree
Undergrad. (yrs 3-4)
Nursing
2
View this sample

It May Not Be Much, but It’s Honest Work!

Here is what we have achieved so far. These numbers are evidence that we go the extra mile to make your college journey successful.

0+

Happy Clients

0+

Words Written This Week

0+

Ongoing Orders

0%

Customer Satisfaction Rate
image

Process as Fine as Brewed Coffee

We have the most intuitive and minimalistic process so that you can easily place an order. Just follow a few steps to unlock success.

See How We Helped 9000+ Students Achieve Success

image

We Analyze Your Problem and Offer Customized Writing

We understand your guidelines first before delivering any writing service. You can discuss your writing needs and we will have them evaluated by our dedicated team.

  • Clear elicitation of your requirements.
  • Customized writing as per your needs.

We Mirror Your Guidelines to Deliver Quality Services

We write your papers in a standardized way. We complete your work in such a way that it turns out to be a perfect description of your guidelines.

  • Proactive analysis of your writing.
  • Active communication to understand requirements.
image
image

We Handle Your Writing Tasks to Ensure Excellent Grades

We promise you excellent grades and academic excellence that you always longed for. Our writers stay in touch with you via email.

  • Thorough research and analysis for every order.
  • Deliverance of reliable writing service to improve your grades.
Place an Order Start Chat Now
image

Order your essay today and save 30% with the discount code Happy