Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Snippet] [Fix] Added a bash snippet #219

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion public/icons/bash.svg

This file was deleted.

20 changes: 20 additions & 0 deletions snippets/bash/system/kill-previous-instances.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
title: Kill Previous Instances
description: Kill all previous instances of a script
author: saminjay
tags: kill,process,background
---

```bash
function kill_prev() {
# $$ contains current pid (grep ignore so it doesn't suicide)
local processes
readarray -t processes < <(pgrep -f "$0" | grep -v "$$")
kill "${processes[@]}" >/dev/null 2>&1
}

# Usage:
# Add this function to your background running script
# It will make sure that only one instance of your script is running at a time
kill_prev
```
6 changes: 3 additions & 3 deletions snippets/bash/system/system-resource-monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ system_resources () {

system_resources "$@"

// Usage:
chmod a+x system-resource-monitor.sh // First make it executable for all the users
# Usage:
chmod a+x system-resource-monitor.sh # First make it executable for all the users

./system-resource-monitor.sh // It will print the following system resources (CPU, RAM, disk, and active users)
./system-resource-monitor.sh # It will print the following system resources (CPU, RAM, disk, and active users)
```
Loading