Last active
August 29, 2015 14:13
-
-
Save groner/51acca4fb08d45582035 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
newpgrp() { | |
# Non-interactive shells don't have job control. Spawn an interactive shell | |
# to create a new process group. The inner non-interactive shell is there | |
# to avoid interactive side-effects later on. | |
$BASH --norc -ic '$BASH -c \"\$@\" -- "$@"' -- "$@" | |
} | |
# Notes on things that don't work: | |
# set -i | |
# You can't turn job control on this way | |
# $BASH -is <<EOF | |
# This will try to run prompt commands from the environment and may create history entries or potentially even truncate the user's history file. | |
This file contains hidden or 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 is sort of portable, right? | |
setsid() { | |
local setsid=$(mktemp -t setsid) exec | |
if test $1 = exec; then | |
exec=exec; shift | |
fi | |
cc -x c - -o $setsid <<-'EOF' && $exec $setsid "$@" | |
#include <unistd.h> | |
#include <stdlib.h> | |
#include <stdio.h> | |
int main(int argc, char *argv[]) { | |
unlink(argv[0]); | |
setsid(); | |
execvp(argv[1], argv+1); | |
perror(argv[1]); | |
exit(1); | |
} | |
EOF | |
} |
This file contains hidden or 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
#!/usr/bin/env bash | |
if test "$1" = report; then | |
ps -o pid,pgid -p $$ | |
else | |
. newpgrp.sh | |
echo plain | |
$BASH $0 report | |
echo -ic -c | |
newpgrp $BASH $0 report | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment