Tag Archives: SIGKILL

Case signal

By Ramesh M

Task 1:

#!/bin/ksh

if [ $# -lt 2 ]
then
echo “Usage : $0 Signalnumber PID”
exit
fi

case “$1” in

1) echo “Sending SIGHUP signal”
kill –SIGHUP $2
;;
2) echo “Sending SIGINT signal”
kill –SIGINT $2
;;
3) echo “Sending SIGQUIT signal”
kill –SIGQUIT $2
;;
9) echo “Sending SIGKILL signal”
kill –SIGKILL $2
;;
*) echo “Signal number $1 is not processed”
;;
esac

./file 9 89876

Output :./file[21]: bad option(s)
I cant kill the process, getting the above error :confused:

Task 2:

When Im tring script called char that checks a single character on the
command line, c. If the character is a digit, digit is displayed. If the
character is an upper or lowercase alphabetic character, letter is
displayed. Otherwise, other is displayed. Have the script print an
error message if the argument c is more than one character in length.

Gimme some idea to reform(correct structure) this below code for the above task

#!/bin/ksh

c=$1
if [[ c -le 9 ]]
then
echo “Proceed “
elif [[ c -eq a-z ]]
then
echo “alphabet”
else
echo “More than one char in length”
fi

case $1 in

1-9) echo “The value is a number”
;;
a-z) echo “the value is a alphabet”
;;
*) echo “Other”
;;
esac

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Martin Pitt: Running a script with unshared mount namespace

When writing system integration tests it often happens that I want to mount some tmpfses over directories like /etc/postgresql/ or /home, and run the whole script with an unshared mount namespace so that (1) it does not interfere with the real system, and (2) is guaranteed to clean up after itself (unmounting etc.) after it ends in any possible way (including SIGKILL, which breaks usual cleanup methods like “trap”, “finally”, “def tearDown()”, “atexit()” and so on).

In gvfs’ and postgresql-common’s tests, which both have been around for a while, I prepare a set of shell commands in a variable and pipe that into unshare -m sh, but that has some major problems: It doesn’t scale well to large programs, looks rather ugly, breaks syntax highlighting in editors, and it destroys the real stdin, so you cannot e. g. call a “bash -i” in your test for interactively debugging a failed test.

I just changed postgresql-common’s test runner to use unshare/tmpfses as well, and needed a better approach. What I eventually figured out preserves stdin, $0, and $@, and still looks like a normal script (i. e. not just a single big string). It still looks a bit hackish, but I can live with that:

#!/bin/sh
set -e
# call ourselves through unshare in a way that keeps normal stdin, $0, and CLI args
unshare -uim sh — -c “`tail -n +7 $0`” “$0” “$@”
exit $?

# unshared program starts here
set -e
echo “args: $@”
echo “mounting tmpfs”
mount -n -t tmpfs tmpfs /etc
grep /etc /proc/mounts
echo “done”

As Unix/Linux’ shebang parsing is rather limited, I didn’t find a way to do something like

#!/usr/bin/env unshare -m sh

If anyone knows a trick which avoids the “tail -n +7″ hack and having to pay attention to passing around “$@”, I’d appreciate a comment how to simplify this.

Source: Planet Ubuntu