Kill nohup process unix - unix

I am running jar using nohup command
nohup java -jar Test.jar
I can't find PID of the jar I am running. I try with:
ps ax | grep java
but it is not listing, then I tried with
ps -ef | grep nohup
and I got this output
root 8503 7529 0 21:52 pts/0 00:00:00 grep nohup
which of the PIDs is PID of nohup process? The first one 8503 is always diffrent, while the second one is the same.

Maybe the program test.jar is finished. See output in nohup.out. To avoid to display grep as a process, use the following pattern:
ps -aux | grep 'j[a]va'
or
ps -aux | grep java | grep -v grep

The following command in your terminal may help you out to run the script using nohup and redirect the output in your desired file.
General Syntax
nohup some_command &> nohup_log_file.out &
Example
nohup python script.py &> nohup_log_script.out &

Related

I ran a script using nohup which calls 3 subscripts inside

nohup ksh mail_failures.ksh >temp.out &
As this script calls another 3 scripts and it runs forever..I couldn't kill this job..I tried below
ps -ef | grep nohup
This command giving only one output with pid..after I killed that and
It showing with the different PID
How can I resolve this?
How can we get the pid of parent?
Everytime I do ps -ef |grep nohup I'm getting only one output..and if I try to kill it again it's saying it coming with a different PID..?

Shell script when executed appears twice is the process list

I am running the below shell script to run in background ./something.sh &
#!/bin/bash
tail -n0 -f -F service.log | while read LOGLINE
do
done
when i check ps -ef| grep something, i see two processes
20273 1 0 16:13 ? 00:00:00 /bin/bash /something.sh
20280 20273 0 16:13 ? 00:00:00 /bin/bash /something.sh
This is because your script is piping the output of a program to a shell command. When you run this there will be three processes:
The something.sh that you explicitly started
The tail that your script starts
A copy of something.sh that is executing the while loop.

How to kill process inside container? Docker top command

I have simple example from official guide at docker website.
I run the following:
sudo docker run -d ubuntu:latest /bin/sh -c "while true; do echo hello world; sleep 1; done"
a66asdasdhqie123...
Then take some output from created container:
sudo docker logs a66
hello
hello
hello
...
Then I lookup the running processes of a container:
sudo docker top a66
UID PID PPID C STIME TTY TIME CMD
root 25055 15152 0 20:07 ? 00:00:00 /bin/sh -c while true; do echo hello world; sleep 1; done
root 25295 25055 0 20:10 ? 00:00:00 sleep 1
Next I try to kill the first process of container:
sudo docker exec a66 kill -9 25055
However after I make it nothing changes. Process still works and output "hello" every second. What do I wrong?
When I reproduce your situation I see different PIDs between docker top <container> and docker exec -it <container> ps -aux. When you do docker exec the command is executed inside the container => should use container's pid. Otherwise you could do the kill without docker straight from the host, in your case: sudo kill -9 25055.
check this:
ps | grep -i a66 | tr -s ' '|cut -f2 -d' '|
{
while read line;
do kill -9 $line;
done
}
to understand this start from executing commands from left till end of each pipe (|)
Simpler option:
kill $(pidof a66)
Took me a while to find the right answer, but you will have to manage this process from within the container. When you run docker top a66 from the host, the PIDs are from your host, although that's not quite the case if using Cygwin. Regardless, you will need to bash or what-have-you back into your container and use commands like ps aux and kill while in the container to find and manage the different PIDs for the same processes there.
i was looking for something like this, but i couldn't find and then i did this:
[root#notebook ~]# docker exec -it tadeu_debian ps aux | grep ping |
awk '{ print $2 }' | xargs -I{} docker exec -i tadeu_debian kill -9
It was two "execs" from Docker e one xargs.
Well, i hope this helps someone!
when you build Docker, use this command :
RUN apt-get install lsof
then in py file you can use:
os.system("lsof /dev/nvidia* | awk '{print $2}' | xargs -I {} kill {}")
REMEMBER: this command kill all process on GPU

execution of a command (unexpected behaviour)

ps -ef | grep "someprocess" output lines contain :
.........................someprocess
.........................ps -ef | grep "someprocess"
Can somebody explain how this gets executed??
If I am checking for a process that is running or not it will allways come as running since
ps -ef | grep "someprocess" will always be there
Of course I know that I can do ps -ef | grep "someprocess" | grep -v 'grep'
But I want to know the process of execution of the above to be clear. why do I get the line that I just executed (ps -ef | grep "someprocess") searching for a process?
From this blog post:
Why does grep show itself? Because the pipe is created by the shell an instant before ps is executed so when the latter searches for all the loaded processes even grep is found.
Or use
pgrep -fl somepattern
that will not show the pgrep process by default
Similarly, pkill will not kill itself :)

uniprocessor or multiprocessor

On unix, how could we know whether the system is multiprocessor or uniprocessor?
Some times we have to answer owr own question :)
On Solaris run the command
/usr/sbin/psrinfo -v|grep "Status of processor"|wc -l
On AIX run the command
lsdev -C|grep Process|wc -l
On HP-UX run the following commands (requires superuser privileges):
P=`echo processor_count/D | adb -k /stand/vmunix /dev/mem |tail -1|awk '{print $2}'` echo "The number of processors on `hostname` = $P"
On Tru64 run the command
/usr/sbin/psrinfo -v|grep "Status of processor"|wc -l
How about
cat /proc/cpuinfo | grep -i 'processor' | wc -l
Or even
dmesg | grep -i cpu
Look out for "Brought up x processors" in the last one
I don't know if it applies to Unix as well, but for Linux, from command line, see here: http://www.howtogeek.com/howto/ubuntu/display-number-of-processors-on-linux/

Resources