Skip to content

Commit 93ccb16

Browse files
authored
[Snippet] [Fix] Added a bash snippet (#219)
* removed bash icon * fix comments of a script * added kill_prev snippet * followed guidelines
1 parent 030861d commit 93ccb16

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

public/icons/bash.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: Kill Previous Instances
3+
description: Kill all previous instances of a script
4+
author: saminjay
5+
tags: kill,process,background
6+
---
7+
8+
```bash
9+
function kill_prev() {
10+
# $$ contains current pid (grep ignore so it doesn't suicide)
11+
local processes
12+
readarray -t processes < <(pgrep -f "$0" | grep -v "$$")
13+
kill "${processes[@]}" >/dev/null 2>&1
14+
}
15+
16+
# Usage:
17+
# Add this function to your background running script
18+
# It will make sure that only one instance of your script is running at a time
19+
kill_prev
20+
```

snippets/bash/system/system-resource-monitor.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ system_resources () {
1515

1616
system_resources "$@"
1717

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

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

0 commit comments

Comments
 (0)