Skip to content

Commit

Permalink
Final
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMousa committed Dec 23, 2023
1 parent b6e2474 commit ac007ad
Show file tree
Hide file tree
Showing 14 changed files with 74 additions and 1 deletion.
4 changes: 4 additions & 0 deletions 0-what-is-my-pid
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# This script displays its PID.

echo $$
7 changes: 7 additions & 0 deletions 1-list_your_processes
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash
# This script displays list of currently running processes
# Must show all processes, for all users, including those which might not have a TTY
# Display a user-oriented format
# Show process hierarchy

ps -a -x -u -f
19 changes: 19 additions & 0 deletions 100-process_and_pid_file
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# This script creates the file /var/run/holbertonscript.pid containing its PID
# Displays To infinity and beyond indefinitely
# Displays I hate the kill command when receiving a SIGTERM signal
# Displays Y U no love me?! when receiving a SIGINT signal
# Deletes the file /var/run/holbertonscript.pid and terminate itself when receiving a SIGQUIT or SIGTERM signal

function love() {
rm /var/run/holbertonscript.pid
exit
}

trap "echo I hate the kill command;love" SIGTERM
trap "echo Y U no love me?!;love" SIGINT

echo $$ >> /var/run/holbertonscript.pid
while [ true ]; do
echo To infinity and beyond;
done
2 changes: 2 additions & 0 deletions 101-manage_my_process
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
# This script INSERT DESCRIPTION HERE
2 changes: 2 additions & 0 deletions 102-zombie.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env bash
# This script INSERT DESCRIPTION HERE
6 changes: 6 additions & 0 deletions 2-show_your_bash_pid
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# This script extends previous exercise command and displays line containing the bash word, this allowing you to easily get the PID of your Bash process
# You cannot use pgrep
# shellcheck disable=SC2009

./1-list_your_processes | grep "bash"
4 changes: 4 additions & 0 deletions 3-show_your_bash_pid_made_easy
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# This script displays the PID, along with process name of processes containing the word bash
# cannot use p s
pgrep -l bash
6 changes: 6 additions & 0 deletions 4-to_infinity_and_beyond
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
# This script displays a statement indefinitely
while true; do
echo "To infinity and beyond"
sleep 2
done
3 changes: 3 additions & 0 deletions 5-dont_stop_me_now
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
# This script kills a process using command kill
kill "$(ps -x | pgrep -f beyond)"
3 changes: 3 additions & 0 deletions 6-stop_me_if_you_can
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
# This script kills 4-to_infinity_and_beyond without kill or killall
pkill -f beyond
11 changes: 11 additions & 0 deletions 7-highlander
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
# This script displays
# to infinity and beyond indefinitely
# With a sleep 2 in between each iteration
# I am invincible!!! when receiving a SIGTERM signal

trap 'echo "I am invincible!!!"' 15
while true; do
echo "to infinity and beyond"
sleep 2
done
3 changes: 3 additions & 0 deletions 8-beheaded_process
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
# This script kills the process 7-highlander
kill -9 "$(pgrep -f highlander)"
2 changes: 1 addition & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1 +1 @@
README.md
0x05. Processes and signals
3 changes: 3 additions & 0 deletions ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
# This script kills 4-to_infinity_and_beyond without kill or killall
pkill -f beyond

0 comments on commit ac007ad

Please sign in to comment.