Question
Windows side ** done in Powershell ** Create a list of all processes within the currently running environment Launch a new application called calculator Create
Windows side
** done in Powershell **
Create a list of all processes within the currently running environment
Launch a new application called calculator
Create a new list of all the processes that are now currently running
Identify the new application by comparing the 2 lists
Hint you might want to use objects
Isolate the process ID
And KILL it
Unix side
Launch a new shell (shell1)
Create a new simple program that loops until it is killed
Launch a new shell (shell2)
Write a shell script that will do the following:
List all of running processes
Determine the PID of the program that you launch
Kill the process using the PID
I need help completing these scripts.
Here is what I have for the Windows side (Powershell), but I don't know how to filter the output for just the ID of the calculator process so that I can kill it.
Get-ExecutionPolicy #Make sure execution policy is set to unrestricted to execute program $firstList = Get-Process #Create a list of all processes currently running in Windows environment Write-Output = $firstList #Output first list of processes Start-Process C:\Windows\System32\calc.exe #Execute calculator program $secondList = Get-Process #Create a new list of all processes currently running in Windows environment (includes calculator process) Write-Output = $secondList #Output second list of processes (chould now contain calc) Compare-Object $firstList $secondList #Use Compare-Object Cmdlet to compare the two lists and identify new application (calc) #Note that "=>" indicates that the calc process was found in the second object, but not the first. This means that the calc process was started after the first list was created.
Here is what I have for the Unix side, however the last line, kill -9 $procID, always brings up an error and I'm not sure why. Please help.:
#!/bin/bash while true do echo "this program will never end..." sleep 6 done
#!/bin/bash ps -ef #list all the running processes echo #create a new line procID= ps -ef | grep simpleLoop.sh | grep -v grep | awk '{print $2}' #create a procces ID variable and filter the simpleLoop process from the list of running processes and cut out grep process #also, take element of 2nd column of each line (in this case just PID of loop process) echo $procID #print process ID of simpleLoop
kill -9 $procID #kill that process
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started