ps, top, pstree
Inspect PID, parent, state, CPU/memory use and hierarchy. A snapshot and a live monitor answer different questions.
Code
Bhavya
Use process tools, file descriptors, fork, exec, wait, pipes and signals to connect textbook state transitions with real system behavior.
ps, top, pstree
Inspect PID, parent, state, CPU/memory use and hierarchy. A snapshot and a live monitor answer different questions.
ls -l, stat, lsof
View permissions/metadata and discover which process holds an open descriptor.
strace
Observe the kernel interface and error codes; avoid exposing secrets in traced arguments.
stdin=0
stdout=1
stderr=2
every call: check return value
fork() Duplicates; exec() ReplacesTwo descriptors represent read and write ends. Create it before fork so both children inherit them.
Each fork returns zero in the child and the child PID in the parent; failure returns −1.
Connect producer stdout to pipe write and consumer stdin to pipe read.
Leaked write descriptors can prevent the reader from ever receiving EOF.
Children replace their images; parent reaps both and interprets exit status.
The user–kernel transition will appear here.
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
int main(void) {
pid_t pid = fork();
if (pid < 0) { perror("fork"); return EXIT_FAILURE; }
if (pid == 0) {
execlp("printf", "printf", "Hello from child\\n", NULL);
perror("exec"); _exit(127);
}
int status;
if (waitpid(pid, &status, 0) < 0) { perror("waitpid"); return EXIT_FAILURE; }
if (WIFEXITED(status)) printf("child exit=%d\\n", WEXITSTATUS(status));
return EXIT_SUCCESS;
}
The child uses _exit after failed exec to avoid flushing inherited buffered streams incorrectly. The parent distinguishes normal exit from signal termination in a fuller program.
ls | wc -l
Mark complete after explaining a two-process pipeline.
Saved in this browser.