Answer this question
Properly
Please find out how many processes and how many threads are created:
pid_t pid;
pid = fork();
if (pid == 0) { /* child process */
fork();
thread_create(...);
}
fork();
a) Write working codes from the pseudo-code above. Add appropriate codes to ensure that you have time to observe processes and threads using ‘top’ and ‘H’ keystroke.
b) Draw a simple diagram showing the processes and threads in their parent/child relationship.
c) Take snapshots of your code’s execution and your observation of the processes/threads.
d) Explain why your code created this number of processes and threads
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
void *work(void * parm) {
printf("Thread Work function\n");
}
int main ()
{
pid_t child_pid1, child_pid2;
pthread_t cThread;
printf ("the main program process ID is %d\n", (int)
getpid());
child_pid1 = fork () ;
// AT this point 2 processes are present
if (child_pid1 == 0) {
printf ("this is the child process1, with id %d\n", (int) getpid
());
int *param = (int *)malloc(2 * sizeof(int));
param[0] = 123;
param[1] = 456;
// Only 1 process can reach the below code
child_pid2 = fork () ;
// at this time, Again 2 process will appear
// So now 2 processes, each will create a new thread..
pthread_create(&cThread, NULL, work, param);
if (child_pid2 > 0)
{
printf ("this is child process1 after forking its child\n");
}
else if (child_pid2 == 0) {
printf ("this is the child process2, with id %d\n", (int) getpid
());
}
}
// 4 processes will reach here..
fork();
// Total 8 processes will reach at this stage
return 0;
}
/// Comments inline.. I do not have a linux system to run the program and check the output.. because system calls like fork will not work on windows system.
Answer this question Properly Please find out how many processes and how many threads are created:...
1. Three threads are created by a process with pid 10. How many threads of execution are there after the creation assuming nothing has time to terminate? 2. Where are the PCBs for processes stored? (i) In an individual process’s memory in user-space. (ii) In a kernel data structure. (iii) Managed by some user-space OS service.
Q1) Including the initial parent process, how many processes are created by the program shown in Figure 1? Give an explanation for your answer. You can include an output statement to test and run the program. A sample output statement could be: printf("Testing......"); #include <stdio.h> #include <unistd.h> int main() { /*fork a child process*/ fork(); /*fork another child process*/ fork(); /*fork another child process*/ fork(); return 0; } Figure 1a - How many processes are created? Another version, now displaying...
including the initial parent process, how many processes are created by the following programs.#include<stdio.h>#include<unistd.h>Main(){Int pid1,pid2;Pid1=fork();Pid2=fork();}
I will provide, best rating. Please help me out understand how to solve part 2 of this problem. I'm not sure how to make this work using ONLY the exec-family. No system() function call. 1. Using either a UNIX or a Linux system, write a C program that forks a child process that ultimately becomes a zombie process. This zombie process must remain in the system for at least 10 seconds. Process states can be obtained from the command: ps...
Question 3: [2+2]a) What, to whom and how many values a fork system call returns? b) Assuming there is no syntax error, what is the output for the following C program for linux? All of you may need to put screenshot of your PC in which Terminal login must be your arid number.int main(){ pid_t fork_return; fork_return = fork(); if (fork_return == 0) { execlp("/bin/ls", "ls", NULL); printf("Child process ID: %d\n", getpid()); exit(0); } else { wait (NULL); printf("Parent process ID: %d\n", getpid()); } return 0;}
Arid No is 19-arid-898Question 3: [2+2]a) What, to whom and how many values a fork system call returns? b) Assuming there is no syntax error, what is the output for the following C program for linux? All of you may need to put screenshot of your PC in which Terminal login must be your arid number.int main(){ pid_t fork_return; fork_return = fork(); if (fork_return == 0) { execlp("/bin/ls", "ls", NULL); printf("Child process ID: %d\n", getpid()); exit(0); } else { wait (NULL); printf("Parent process ID: %d\n",...
This is for a Unix class. Please help me out. I am attaching a skeletal code of the program below, it just needs ti be filled in. Below is a skeletal code of the program. Fork a child process and then use the parent for reading and the child for writing. This is just a way of sending and receiving messages asynchronously. /* ************************************************************* * Utility functions * ************************************************************** */ static void usageError(const char * progName, const char *msg) {...
I have the following code....from the previous lab....the above needs to be added to what is already existing. ALSO MODIFY SEMAPHORES TO USE pthreads instead of the pipe constructs P() & V() #include <stdio.h> #include <string.h> #include <sys/types.h> #include <unistd.h> #include <sys/wait.h> #include <stdlib.h> #include <sys/stat.h> void printStat(char *filename); //Main int main(int argc, char *argv[]) { //Process Id (storing) pid_t pid; int j; //printf("Welcome to Project Three\n”); // For loop*/ for (j = 1; j...
JAVA 3 PLEASE ANSWER AS MANY QUESTIONS AS POSSIBLE! ONLY 2 QUESTIONS LEFT THIS MONTH!!! Question 12 pts Which is a valid constructor for Thread? Thread ( Runnable r, int priority ); Thread ( Runnable r, String name ); Thread ( int priority ); Thread ( Runnable r, ThreadGroup g ); Flag this Question Question 22 pts What method in the Thread class is responsible for pausing a thread for a specific amount of milliseconds? pause(). sleep(). hang(). kill(). Flag...
Please read and answer the following questions. 1. How was the sample selected ? We’re demographics collected ? 2. Is the sample representative of the target population? If not how was the sample “improved “ to make the results more reliable and valid? 3. What is the design of the study? 4. How were the human subjects protected ? 5. Were instruments used reliable and valid ? Did they measure the phenomenon under the study( how do you know that...