In a bash script, I'm using kill -0 to test if I have permission to kill a process. There are 3 cases:
- the process exists and I have permission: OK
- the process doesn't exist and it's OK (because I decided to ignore processes that are already dead).
- I don't have permission and I want to raise an error.
If I use ps $pid, I cannot tell the difference between a process that does not exist and a process I cannot "see":
If I use kill -0 $pid, I could tell the difference reading stderr but it would be language specific: Question: How can I programmatically tell if a process exists and if I have permission on it?
I wasn't sure if I should post it here of in the Shell Script category, but I figured it was definitely a newbie question.
I'm trying to write a script that will check for the existence of a specific file (or for any files within the directory) and then take specific actions. I've removed all... (2 Replies)
Hey all,
I have total new with shell scripting so I don't know if what I need to do even possible, here it is...for a duration of time (say...1 hour) I need to check for the existence of a particular file, if it exists then I will invoke a java program or I will continue to check until a)... (2 Replies)
Hello,
I have this process app.fcgi and a directory containing images. I'd like to ensure that only app.cgi can access those images and more generally that folder.Thanks! (1 Reply)
Hi
I want to check a particular file is available or not. But i know only the pattern of that file sat AB1234*.txt.I need the latest file name and it ll be used in the script. How can i do this using ls -ltr command.
Thanks,
LathishSundar V (2 Replies)
Hi,
I want to make a bash script which is running like :
1.sh http://www. google.com
and check if the url does exist printing a message.
I want to save the source code of this page in a file.
Could you help me ? (4 Replies)
Hi
I'm using the below command in shell script to check for file exists in the path
if
.....
fi
path and test are variables
path and the file exists but the commands inside if condition is executed (! operator used)
Is the above way of checking for file existence is correct?
... (4 Replies)
Hope someone can help me on this
In a directory ,files are dynamically generated.I need a script to do the following
if files are not received for more than 2 hours or if the received file is empty
then do something
How can I put that in a script.Thank you
eg. in cd /dir_name the... (13 Replies)
I'm on AIX. I have triggered an infinite loop process (to keep looking for input file availability for further process). At present only I can kill the process.
In case my colleague wants to kill the process for any reason, how do I provide permission to others to kill the process?
Currently... (3 Replies)
Discussion started by: krishmaths
3 Replies
LEARN ABOUT OPENSOLARIS
kill
kill(2) System Calls kill(2)NAME
kill - send a signal to a process or a group of processes
SYNOPSIS
#include <sys/types.h>
#include <signal.h>
int kill(pid_t pid, int sig);
DESCRIPTION
The kill() function sends a signal to a process or a group of processes. The process or group of processes to which the signal is to be
sent is specified by pid. The signal that is to be sent is specified by sig and is either one from the list given in signal (see sig-
nal.h(3HEAD)), or 0. If sig is 0 (the null signal), error checking is performed but no signal is actually sent. This can be used to check
the validity of pid.
The real or effective user ID of the sending process must match the real or saved (from one of functions in the exec(2) family) user ID of
the receiving process, unless the privilege {PRIV_PROC_OWNER} is asserted in the effective set of the sending process (see Intro(2)), or
sig is SIGCONT and the sending process has the same session ID as the receiving process. A process needs the basic privilege
{PRIV_PROC_SESSION} to send signals to a process with a different session ID. See privileges(5).
If pid is greater than 0, sig will be sent to the process whose process ID is equal to pid.
If pid is negative but not (pid_t)-1, sig will be sent to all processes whose process group ID is equal to the absolute value of pid and
for which the process has permission to send a signal.
If pid is 0, sig will be sent to all processes excluding special processes (see Intro(2)) whose process group ID is equal to the process
group ID of the sender.
If pid is (pid_t)-1 and the {PRIV_PROC_OWNER} privilege is not asserted in the effective set of the sending process, sig will be sent to
all processes excluding special processes whose real user ID is equal to the effective user ID of the sender.
If pid is (pid_t)-1 and the {PRIV_PROC_OWNER} privilege is asserted in the effective set of the sending process, sig will be sent to all
processes excluding special processes.
RETURN VALUES
Upon successful completion, 0 is returned. Otherwise, -1 is returned, no signal is sent, and errno is set to indicate the error.
ERRORS
The kill() function will fail if:
EINVAL The sig argument is not a valid signal number.
EPERM The sig argument is SIGKILL and the pid argument is (pid_t)-1 (that is, the calling process does not have permission to send the
signal to any of the processes specified by pid).
The effective user of the calling process does not match the real or saved user and the calling process does not have the
{PRIV_PROC_OWNER} privilege asserted in the effective set, and the calling process either is not sending SIGCONT to a process
that shares the same session ID or does not have the {PRIV_PROC_SESSION} privilege asserted and is trying to send a signal to a
process with a different session ID.
ESRCH No process or process group can be found corresponding to that specified by pid.
USAGE
The sigsend(2) function provides a more versatile way to send signals to processes.
ATTRIBUTES
See attributes(5) for descriptions of the following attributes:
+-----------------------------+-----------------------------+
| ATTRIBUTE TYPE | ATTRIBUTE VALUE |
+-----------------------------+-----------------------------+
|Interface Stability |Standard |
+-----------------------------+-----------------------------+
|MT-Level |Async-Signal-Safe |
+-----------------------------+-----------------------------+
SEE ALSO kill(1), Intro(2), exec(2), getpid(2), getsid(2), setpgrp(2), sigaction(2), sigsend(2), signal(3C), signal.h(3HEAD), attributes(5), privi-
leges(5), standards(5)SunOS 5.11 22 Mar 2004 kill(2)