-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add set_rtprio_limit utility for OpenSmalltalk VMs
- Loading branch information
Showing
4 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |