Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

system call is a function call to the kernel (O/S). Select one: True False Someo

ID: 3814270 • Letter: S

Question

system call is a function call to the kernel (O/S).

Select one:

True

False

Someone asks you to write a c code to sort the contents of a file. You feel lazy and don't want to write the whole code but use the system call and sort command. What would be your program?

Select one:

a. #include <stdio.h>
main()
{
system("sort file.txt > sorted-file.txt");
}

b. #include <stdio.h>
main()
{
system("sort", "file.txt > sorted-file.txt");
}

c. #include <stdio.h>
main()
{
sort file.txt > sorted-file.txt;
}

d. #include <stdio.h>
main()
{
system(sort file.txt > sorted-file.txt);
}

What would be the most likely output of the following program (assume there are no unexpected waits)?

#include <stdio.h>
#include <unistd.h>

main()
{
int i,j;

i=fork();
for (j=0; j<3; j++)
{
if (i == 0 && j == 0)
    {
    sleep(3);
    printf("Cats ");
    }
else if (i == 0)
    {
    sleep(2);
    printf("Dogs ");
    }
else
    {
    sleep(2);
    printf("Raining ");
    }
}
}

Select one:

a. Raining
Cats
Raining
Dogs
Raining
Dogs

b. Raining
Cats
Dogs
Raining

c. Cats
Dogs
Raining

d. Raining

A signal is a message from one process to another.

Select one:

True

False

What will be the output of the following program?

#include <stdio.h>
#include <stdlib.h>
main()
{
char text[80];
printf("Ready to system()... ");
sprintf(text,"date -u");
system(text);
printf("Did it work? ");
sleep(2);
printf("Indeed it did. ");
}

Select one:

a. Ready to system()...
(date from system)
Did it work?
Indeed it did.

b. Ready to system()...
(date from system)

c. Did it work?
Indeed it did.

d. Ready to system()...
(date from system)
Did it work?

Explanation / Answer

system call is a function call to the kernel (O/S).

Answser: False

Someone asks you to write a c code to sort the contents of a file. You feel lazy and don't want to write the whole code but use the system call and sort command. What would be your program?
Select one:
Answer:
Option b. #include <stdio.h>
main()
{
system("sort", "file.txt > sorted-file.txt");
}

What would be the most likely output of the following program (assume there are no unexpected waits)?

Answer: Option d.Raining

Raining

Raining

Program:

#include <stdio.h>
#include <unistd.h>

main()
{
int i,j;

i=fork();
for (j=0; j<3; j++)
{
if (i == 0 && j == 0)
{
sleep(3);
printf("Cats ");
}
else if (i == 0)
{
sleep(2);
printf("Dogs ");
}
else
{
sleep(2);
printf("Raining ");
}
}
return 0;
}
Output:

Raining
Raining
Raining

A signal is a message from one process to another.

Select one:

Answer: True

What will be the output of the following program?

Answer: Option a Ready to system()...

(date from system)

Did it work?

Indeed it did.

Program:

#include <stdio.h>
#include <stdlib.h>
main()
{
char text[80];
printf("Ready to system()... ");
sprintf(text,"date -u");
system(text);
printf("Did it work? ");
sleep(2);
printf("Indeed it did. ");
}

Output:

Mon Apr 10 02:15:11 UTC 2017
Ready to system()...
Did it work?
Indeed it did.