ANSWER
GIVEN BY
fork() process create a new child process for the recent process, which shares the matching resources as by the current method(parent process).
when fork() is called, if the go back value is 0, it means child process was effectively created.
wait() process makes the up to date process to wait (does'nt allow to advance to execute code) untill existing child route exits.
In this case,
i = 0
j = 0
i = fork()
if child process was formed productively, we print j value which is 5
Untill child finish its execution, process is set aside on hold (if we dont use wait its kinda multithreading then) and then route id of child is returned and assign to j (j = pid of childprocess).
Overall the plan is a demo of fork() and wait().
What is the functionality of the following code? #include #include mainO <stdio.h> <unistd.h> int i,j; j-0:...
Source code to modify: #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { pid_t pid; /*fork a child process*/ pid = fork(); if (pid<0){ /*error occured*/ fprintf(stderr,"Fork failed\n"); return 1; } else if (pid == 0) { /*child process */ printf("I am the child %d\n",pid); execlp("/bin/ls","ls",NULL); } else { /*parent process */ /*parent will wait for the child to complete*/ printf("I am the parent %d\n",pid); wait(NULL); printf("Child Complete\n"); } return 0; } 1. Write program codes for 3.21 a and...
What is the output? #include <sys/types.h> #include <sys/wait.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main() { int x = 5; int y = 2; int z = 30; x = fork(); y = fork(); if (x != 0) printf("Type 1\n"); if (y != 0) printf("Type 2\n"); z = fork(); if (x > 0 || y > 0 || z > 0) printf("Type 3\n"); if (x == 0 && y == 0 && z != 0) printf("Type 4\n"); if (x...
QUESTIONS What will be the output of the following C code? 1. #include <stdio.h> int maino int 1 - -3; int k - * % 2; printf(\n", k); Compile time error O-1 Implementation defined
GIVEN CODE- FILL IN THE BLANK! #include <fcntl.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/wait.h> // Function ptototypes int readX(); void writeX(int); int main() /// chi read x ---> divi ---> write x into file ---> par read x --> sub--> write x into file---> chi read x-->etc { int pid; // pid: used to keep track of the child process int x = 19530; // x: our value as integer ...
What is printed when the following code is executed? #include <stdio.h> int main() { for (int i=3, j=5; i>=0; i-=2, j+=j*i) { printf("%d", j); منم }
9. Which of the following is true for the following program? #include <stdio.h> int maino int i = 1; switch (0) case 1: printf("%d", 0); case 2: printf("%d", 0); case 3: printf("%d", 0); default: printf("%d", 1); return 0; } (2 points) The program has no error, the output is 1111 The program has no error, the output is 1 The program produces a compile time error, because there are no break statements The program produces a compile time error, because...
include<stdio.h> #include<pthread.h> int i=4 ,j=10; void*childfunc(void *p) { printf("child here.i=%d,j=%d\n",i,j); i*=3; j*=3; printf("child here.i=%d,j=%d\n",i,j); } void main() { pthread_t child1; pthread_create(&child, Null,childfunc, Null) pthread_join(child,Null); printf("parent here.i=%d,j=%d\n",i,j); i*=2; j*=2; printf("end of program .i=%d,j=%d\n",i,j); } what is output?
Read the following code and fill the following blanks (no space is allowed): #include <stdio.h> int maino inta - 55: int*pa &a; "An integer" /* A pointer to an integer" int *ppa = &pa; /* A pointer to a pointer to an integer printf("The content of a is %d\n", printf("The address of a is %p\n", printf("The content of pa is %p\n", printf("The address of pa is %p\n", printf("The dereferenced value of pa is %d\n", printf("The content of ppa is pln",...
#include<stdio.h> eint main() { int i = 0, j = 0; while (i < 10|| j < 7) { i++; j++; } printf("%d, %d\n", i, j); getchar(); return 0; } 01,01 10,10 7.7 10,7