回答編集履歴

1

追記

2018/01/21 10:23

投稿

nullpon
nullpon

スコア5737

test CHANGED
@@ -8,10 +8,72 @@
8
8
 
9
9
  pidfile="/var/run/${name}.pid"
10
10
 
11
+
12
+
11
13
  [[ -f "$pidfile" ]] && exit 0
14
+
15
+
12
16
 
13
17
  trap "rm -f -- '$pidfile'" EXIT
14
18
 
15
19
  echo $$ > "$pidfile"
16
20
 
17
21
  ```
22
+
23
+
24
+
25
+ 追記
26
+
27
+ 子スクリプト対応バージョン
28
+
29
+ ```bash
30
+
31
+ --- parent_script.sh ---
32
+
33
+ #!/bin/bash
34
+
35
+ name=`basename $0`
36
+
37
+ pidfile="/var/run/${name}.pid"
38
+
39
+
40
+
41
+ script_name1=child_script1.sh
42
+
43
+ script_name2=child_script2.sh
44
+
45
+ pidfile1="/var/run/${script_name1}.pid"
46
+
47
+ pidfile2="/var/run/${script_name2}.pid"
48
+
49
+
50
+
51
+ [[ -f "$pidfile" -o -f "$pidfile1" -o -f "$pidfile2" ]] && exit 0
52
+
53
+
54
+
55
+ trap "rm -f -- '$pidfile'" EXIT
56
+
57
+ echo $$ > "$pidfile"
58
+
59
+
60
+
61
+ --- child_script1/2.sh ---
62
+
63
+ #!/bin/bash
64
+
65
+ name=`basename $0`
66
+
67
+ pidfile="/var/run/${name}.pid"
68
+
69
+
70
+
71
+ [[ -f "$pidfile" ]] && exit 0
72
+
73
+
74
+
75
+ trap "rm -f -- '$pidfile'" EXIT
76
+
77
+ echo $$ > "$pidfile"
78
+
79
+ ```