Question

In Unix, the first process is called init. All the others are descendants of “init”. The...

In Unix, the first process is called init. All the others are descendants of “init”. The init process spawns a sshd process that detects a new secure ssh requested connection (WKPort 22). Upon a new connection, sshd spawns a login process that then loads a shell on it when a user successfully logs into the system. Now, assume that the user types

who | grep <uwnetid> | wc –l

Draw a process tree from init to those three commands. Add fork, exec, wait, and pipe system calls between any two processes affecting each other.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please find the explanation for process tree and how its linked to init process. Also i have given sample program which will create the process under init.

Process Tree:

It is a schematic diagram which shows the process as tree and we can easily understand how process are interrelated. We can also identify how the parent/child processes are related.

Please let me know if you require more info.

Answer:

Following is the output from pstree command when we execute "who|grep <uwnetid>|wc -l"

init

├─sshd───sshd //This represents sshd daemon is running under init which will handle ssh connections
│─sshd──sshd───sshd───bash─┬─grep // shows ssh connection established and the cmd is ran from bash
│ ├─wc
│ └─who

Process tree diagram:

Following is the process tree diagram when we use fork, pipe, wait system calls.

├─sshd───sshd
├─sshd─┬─sshd───sshd───bash───forkpipie.exe───forkpipie.exepstree


We have got the above process tree from below sample c program:

#include <stdio.h>
#include <unistd.h>
#define MSGSIZE 16

char* msg1 = "fork calls";
char* msg2 = "exec calls";
char* msg3 = "pipe calls";

int main()
{
char inbuf[MSGSIZE];
int p[2], pid, nbytes;

if (pipe(p) < 0)
exit(1);

/* continued */
if ((pid = fork()) > 0) {
write(p[1], msg1, MSGSIZE);
write(p[1], msg2, MSGSIZE);
write(p[1], msg3, MSGSIZE);


/* close(p[1]); */
wait(NULL);
}

else {

/* close(p[1]); */
while ((nbytes = read(p[0], inbuf, MSGSIZE)) > 0)
printf("% s\n", inbuf);
if (nbytes != 0)
exit(2);
printf("Finished reading\n");
}
return 0;
}

Output: You can run this program and this hangs after the execution. Then you can execute pstree to identify how process tree looks like.

Process tree diagram for Fork, wait, pipe:

Add a comment
Know the answer?
Add Answer to:
In Unix, the first process is called init. All the others are descendants of “init”. The...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In UNIX Write a script that checks each minute and reports on who logs in and...

    In UNIX Write a script that checks each minute and reports on who logs in and who logs out. You can follow the steps below (not the only way): Using the commands who and cut, extract the list of usernames currently logged in the system To check after a minute, the sleep command can be used: sleep 60 Get the new list of users logged in after a minute For each user in the list; check if he is in...

  • Using Unix processes Submit a README file that lists the files you have submitted along with...

    Using Unix processes Submit a README file that lists the files you have submitted along with a one sentence explanation. Call it Prj1README. MakeCopy.c : Write a C program that makes a new copy of an existing file using system calls for file manipulation. The names of the two files and copy block sizes are to be specified as command line arguments. Open the source file in read only mode and destination file in read/write mode. ForkCopy.c : Write a...

  • Please type your answer, thank you! :) The subject is UNIX Using the BASH for and...

    Please type your answer, thank you! :) The subject is UNIX Using the BASH for and while loops (Textbook question 13.19 page 403) Write a script that checks each minute and reports on who logs in and who logs out. You can follow the steps below (not the only way): Using the commands who and cut, extract the list of usernames currently logged in the system To check after a minute, the sleep command can be used: sleep 60 Get...

  • Project 1: Implementing a Shell 1 Overview In this individual project you will have to design...

    Project 1: Implementing a Shell 1 Overview In this individual project you will have to design and implement a simple shell command interpreter called mysh. The basic function of a shell is to accept lines of text as input and execute programs in response. The shell must be able to execute built-in commands in a process different from the one executing mysh. 2 Requirements When first started, your shell should initialize any necessary data structures and then enter a loop...

  • This project consists of designing a C program to serve as a shell interface that accepts...

    This project consists of designing a C program to serve as a shell interface that accepts user commands and then executes each command in a separate process. A shell interface gives the user a prompt, after which the next command is entered. The example below illustrates the prompt cse222> and the user’s next command: cat prog.c. cse222> cat prog.c One technique for implementing a shell interface is to have the parent process first read what the user enters on the...

  • Hello all, I have a c++/unix (bash) question. I am struggling on starting this assignment. If...

    Hello all, I have a c++/unix (bash) question. I am struggling on starting this assignment. If you could start the assignment and tell me how to do the rest it would be greatly appreciated! (Quick thumbs up answer response if thorough and correct) Maintain automobile records in a database Write a shell script to create, view and modify a simple database that contains automobile records. The shell script has to be done in Bourne shell syntax (bash as a matter...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT