I am trying to kill a backend process i know i can type a simple command
kill -9 pid and my process will be killed.
But the task is that there are two commands in the script which run the backend process and when that script is runned then we cannot find the PID of the two commands
So how can we kill them ....i Tried using 2> such that output on screen goes to the file name mentioned but the may be i m using a wrong syntex....
tail -f inputfile >> o/pfile & 2> pid
where pid is the file where i want the pid of this command such that i can kill the same....
ptree Print the process trees containing the specified pids
or users, with child processes indented from their
respective parent processes. An argument of all digits
is taken to be a process-id, otherwise it is assumed
to be a user login name. Default is all processes.
get the PPID of the script/process name & do ptree <PPID>
you will find the PID's of all processes (parent as well as child ).Do NOT stop the system daemons.
But the task is that there are two commands in the script which run the backend process and when that script is runned then we cannot find the PID of the two commands
So how can we kill them
Since there are two processes running in the script,they will have varying PID's ,so you try killing parent PID first & then the parent shell itself.
Actually, redirecting the stderr of the command that you run is not going to help. What you might have to do is redirect the stderr of the shell that is executing the commands. I am not too sure about that though.
In nawk, using -v allows you to pass a shell variable to the awk command as an awk variable. I am passing the $$ (pid of the shell script in this case) as the awk variable.
Then inside the nawk, the !/ps/ and !/nawk/ make sure that the ps and the nawk commands do not match (it will not really matter if they do). The awk itself, checks for a process that has the process id of the shell script as its parent process id (the third field in the ps -ef command is the ppid). In this case, the two tail -f commands will show up.
Hope that helps.