aboutsummaryrefslogtreecommitdiff
path: root/libbutl/utility.bash.in
blob: 5f51a2cbd3669e85c42d611a952a0bae46f48268 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# file      : libbutl/utility.bash.in
# license   : MIT; see accompanying LICENSE file

if [ "$butl_utility" ]; then
  return 0
else
  butl_utility=true
fi

if (( BASH_VERSINFO[0] < 4 || BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] < 3 )); then
  echo 'error: bash 4.3 or later is required' 2>&1
  exit 1
fi

# Return the libbutl/ module directory.
#
# This is used to run the binding support executables.
#
function butl_path ()
{
  # BASH_SOURCE[0] contains the source path of the function being executed
  # (that is, us).
  #
  dirname "${BASH_SOURCE[0]}"
}

# Resume a stopped process execution by sending it the SIGCONT signal.
#
# Note that to avoid races the function waits until the process enters the
# stopped state.
#
function butl_resume_process () # <pid>
{
  local pid="$1"

  while true; do

    # Note that while the ps's -o option 'state' value is not specified by
    # POSIX, it is supported by all the major implementations with the leading
    # 'T' character indicating the 'stopped' process run state.
    #
    local s
    s="$(ps -p "$pid" -o state=)"

    if [ "${s:0:1}" == "T" ]; then
      kill -SIGCONT "$pid"
      break
    fi
  done
}