In: Computer Science
Write shell script code that displays the process tree on a Linux machine. The process tree should show the process identifier of each process. Those processes that have the same ancestor should be sorted by process identifier instead of by name. The process tree should show the full names of all threads, if any and available. Whenever the user identifier associated with a process differs from the user identifier associated with the parent of that process, the process tree should show the transition.
#!/bin/bash
while [[ $REPLY != x ]]; do
clear
echo -e "Launch utilities:\n 1. Process Tree\n 2. Process States\n 3. Threads\n"
read -p "Enter selection [1-3], or type x to exit: " REPLY
if [ $REPLY == 1 ]; then
echo -e "\n"
#identify a command that displays the tree of
processes in Linux
#identify the options of the command you have found that meet the
requirements described in section "Process Tree" of the description
of Homework 03
#put the command here, followed by the options. For example, if the
command is called displayprocesstree, and the options are -a, -b,
and -c, the command would appear as follows:
# displayprocesstree -abc
read void
clear
fi
if [ $REPLY == 2 ]; then
#identify the command that displays a list of processes on the
system. identify the options of that command that can include the
state of each process in the output
read void
clear
fi
if [ $REPLY == 3 ]; then
#display a string that asks the user to enter the pid of one of the
processes
#read a pid from the user onto a variable
# display the threads created by that process
read void
clear
fi
done
#!/bin/bash
while [[ $REPLY != x ]]; do
clear
echo -e "Launch utilities:\n 1. Process Tree\n 2. Process States\n 3. Threads\n"
read -p "Enter selection [1-3], or type x to exit: " REPLY
if [ $REPLY == 1 ]; then
echo -e "\n"
pstree -psa $$
ps -aef --forest
read void
clear
fi
if [ $REPLY == 2 ]; then
ps u
read void
clear
fi
if [ $REPLY == 3 ]; then
read -p "Enter PID: " p_id
ps -T -p $p_id
read void
clear
fi
done
Code | Meaning |
---|---|
D | Uninterruptible sleep (usually IO) |
R | Running or runnable (on run queue) |
S | Interruptible sleep (waiting for an event to complete) |
T | Stopped, either by a job control signal or because it is being traced. |
W | paging (not valid since the 2.6.xx kernel) |
X | dead (should never be seen) |
Z | Defunct (“zombie”) process, terminated but not reaped by its parent. |
Code | Meaning |
---|---|
< | high-priority (not nice to other users) |
N | low-priority (nice to other users) |
L | has pages locked into memory (for real-time and custom IO) |
s | is a session leader |
l | is multi-threaded (using CLONE_THREAD, like NPTL pthreads do) |
+ | is in the foreground process group |
if you have any doubt then please ask me without any hesitation
in the comment section below , if you like my answer then please
thumbs up for the answer , before giving thumbs down please discuss
the question it may possible that we may understand the question
different way and we can edit and change the answers if you argue,
thanks :)