Question

In: Computer Science

Write shell script code that displays the process tree on a Linux machine. The process tree...

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

Solutions

Expert Solution

#!/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 :)


Related Solutions

Write shell script code that displays a list of all active processes in the system. Lift...
Write shell script code that displays a list of all active processes in the system. Lift the BSD-style “only yourself” restriction. The output should show the status of the processes. #!/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...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt the user to "Enter a number between 1 and 10". (Hint: Use the 'echo' and 'read' commands in the script. See the slide about the 'read' command) If the number is less than 5, print "The number is less than 5" (Hint: You will read input into a variable; e.g. read NUM. In the IF statement, enclose $NUM in quotes; e.g. "$NUM". Also, remember...
Write shell script code that shows all threads created by a given process. The user will...
Write shell script code that shows all threads created by a given process. The user will provide the process identifier of that process. #!/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...
Perl is a programming language that can be used on Linux. Write a Perl shell script...
Perl is a programming language that can be used on Linux. Write a Perl shell script named phone.pl that prompts the user to enter first or last or any portion of person’s name, so that can be found the appropriate entry in the phone directory file called “phones”. If the user tries to enter name as the argument on the command line, he/she will get a warning message “You need to provide name when prompted by this script!” If the...
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string...
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string expressed as -rwxrwxrwx and prints out whether or not theobject is a directory, file or link. The string is read in from standard input. Convert String (Part 2) Modify the script so its able to print out the octal permission which the string represents along with the file type. This is in addition to part 1. Convert String (Part 3) For the script in...
Linux Sign into your lab account Write a bash shell script that does the following: Print...
Linux Sign into your lab account Write a bash shell script that does the following: Print out a friendly welcome message Ask the user for the name of their favorite animal Grep that animal from a text file noises.txt Tell the user what that animal says (i.e. what noise does it make) If the animal does not exist ask the user what noise the animal makes Store that new information in noises.txt
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within...
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within your script  Provide user feedback  Use loops  Use conditionals Remember to use chmod +x to make your file executable! Each script is 5 points in the Specifications portion of the rubric. Don’t forget to maintain good standards and comments. Script 1 – Echo-back some information Write a script name hello.sh that will take the user’s first name as a command line...
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given...
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given only two integer numbers from command line arguments and computing their multiplication. If two integer numbers are not given, print “Wrong Input” on your screen. Note that, the number of arguments is known when the script runs. Take a screenshot showing your shell program and its execution step. Design a shell program to remove all the shell programming files ending with sh on your...
Linux Shell Prpgramming 1.Write a quiz-script which will provide some statistics about a quiz results (summarize...
Linux Shell Prpgramming 1.Write a quiz-script which will provide some statistics about a quiz results (summarize how many good answers and how many wrong answers were provided). The script should use up to 3 execution parameters. When executed with two parameters (let’s call it interactive mode), it should assume, that the first file contains a list of questions and the second file contains correct answers to these questions. In such execution case your script should display questions one by one...
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell...
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell script to take a directory as an argument and display the contents of that directory (10pts) Write a shell script that takes any command as a parameter and displays help on that command (e.g. the result of the execution of man <command>). (10pts) Write a shell script that requires two file names as parameters and copies content of one file into another without asking...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT