Typing ps alone lists the current running processes. lab3.c can be compiled as, gcc –o lab3 lab3.c. The output of the program can be obtained by typing: ./lab3. Below are the examples of the possible outputs that would be generated by the ps and ./lab3 commands: ps ./lab3 PID TTY TIME CMD 13043 pts/0 00:00:00 bash 13133 pts/0 00:00:00 ps Process ID is: 13126 Parent Process ID is 13125 Process ID is: 13125 Parent Process ID is 13124 Process ID is: 13127 Parent Process ID is 13124 Process ID is: 13124 Parent Process ID is 13043 Please remember that PID value of bash (Unix command shell) is 13043 for this example. So the process tree can be drown by using the above information as: Write the output of your program and draw a process three and label the processes with their process IDs. Output Process Tree Process ID is: _________ Parent Process ID is _________ Process ID is: _________ Parent Process ID is _________ Process ID is: _________ Parent Process ID is _________ Process ID is: _________ Parent Process ID is _________
- Typing ps alone lists the current running processes. lab3.c can be compiled as, gcc –o lab3 lab3.c. The output of the program can be obtained by typing: ./lab3. Below are the examples of the possible outputs that would be generated by the ps and ./lab3 commands:
ps |
./lab3 |
PID TTY TIME CMD 13043 pts/0 00:00:00 bash 13133 pts/0 00:00:00 ps
|
Process ID is: 13126 Parent Process ID is 13125 Process ID is: 13125 Parent Process ID is 13124 Process ID is: 13127 Parent Process ID is 13124 Process ID is: 13124 Parent Process ID is 13043 |
Please remember that PID value of bash (Unix command shell) is 13043 for this example. So the process tree can be drown by using the above information as:
Write the output of your program and draw a process three and label the processes with their process IDs.
Output |
Process Tree |
Process ID is: _________ Parent Process ID is _________ Process ID is: _________ Parent Process ID is _________ Process ID is: _________ Parent Process ID is _________ Process ID is: _________ Parent Process ID is _________ |
|
- Use pico to type and save the following program as labrep.c. Compile and run the program to observe that fork() returns the value of the child’s PID to the parent process and zero to the child process. (You don’t have to type the comments.)
#include <stdio.h>
#include <stdlib.h>
main ( )
{
int result ;
printf("%d: I am the parent. Remember my number!\n", getpid( ) );
printf("%d: I am now going to fork ... \n", getpid( ) );
result = fork ( ) ;
if (result != 0)
{ /* the parent will execute this code */
printf("%d: My child's pid is %d\n", getpid ( ), result );
}
else /* result == 0 */
{ /* the child will execute this code */
printf("%d: Hi ! I am the child.\n", getpid ( ) ) ;
exit (1) ;
}
printf("%d: like father like son. \n", getpid ( ) );
}
Write the output of the program. Draw a process three and label the processes with their process IDs.
Output |
|
Process Tree |
|
Step by step
Solved in 2 steps with 1 images