Skip to content

Commit

Permalink
Add set_rtprio_limit utility for OpenSmalltalk VMs
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Nov 6, 2016
1 parent 4b569e5 commit 1c186d1
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ matrix:
- language: bash
smalltalk:
sudo: false
script: bash tests/all_tests.sh
script: tests/all_tests.sh

# Test that smalltalkCI can fail
- smalltalk: Squeak-5.0
Expand Down
2 changes: 2 additions & 0 deletions tests/all_tests.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ echo "======================================================"
echo "======================================================"
"${BASE}/squeak_tests.sh" || status=$?
echo "======================================================"
"${BASE}/utils_tests.sh" || status=$?
echo "======================================================"

exit "${status}"
17 changes: 17 additions & 0 deletions tests/utils_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

readonly BASE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
source "${BASE}/helpers.sh"


test_set_rtprio() {
if [[ "$(uname -s)" != "Linux" ]]; then
return
fi
gcc -o "set_rtprio_limit" "${BASE}/utils/set_rtprio_limit.c"
if [[ ! -f "set_rtprio_limit" ]]; then
fail "set_rtprio_limit should exist"
fi
}

source "${BASE}/lib/shunit2"
46 changes: 46 additions & 0 deletions utils/set_rtprio_limit.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Set rtprio to 2:2 for a given pid (required to run OpenSmalltalk VMs).

#define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/resource.h>

#define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \
} while (0)

int main(int argc, char *argv[]) {
struct rlimit old, new;
struct rlimit *newp;
pid_t pid;

if (!(argc == 2)) {
fprintf(stderr, "Usage: %s <pid>\n", argv[0]);
exit(EXIT_FAILURE);
}

pid = atoi(argv[1]); /* PID of target process */

new.rlim_cur = 2;
new.rlim_max = 2;
newp = &new;

/* Set RTPRIO limit of target process; retrieve and display
previous limit */

if (prlimit(pid, RLIMIT_RTPRIO, newp, &old) == -1)
errExit("prlimit-rtprio-1");
printf("Previous limits: soft=%lld; hard=%lld\n",
(long long) old.rlim_cur, (long long) old.rlim_max);

/* Retrieve and display new RTPRIO limit */

if (prlimit(pid, RLIMIT_RTPRIO, NULL, &old) == -1)
errExit("prlimit-rtprio-2");
printf("New limits: soft=%lld; hard=%lld\n",
(long long) old.rlim_cur, (long long) old.rlim_max);

exit(EXIT_SUCCESS);
}

0 comments on commit 1c186d1

Please sign in to comment.