How do I find the name of a process in linux? - linux

I'm really struggling with how to find processes by name in linux. I'm sure it's probably something simple that I'm missing.

Are you looking for the command ps ?
Here an example
nabil#LAPTOP:~$ ps xua | grep python
rootwsl 327 0.0 0.1 29568 17880 ? Ss Jan30 0:02 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
rootwsl 411 0.0 0.1 108116 20740 ? Ssl Jan30 0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
nabil 106387 0.0 0.0 3444 736 pts/1 S+ 23:26 0:00 grep --color=auto python

Related

Run Webserver in the background

In order to have my site running on a webserver i have to manualy login into it with these commands:
ssh IP
add password
cd chn
source bin/activate
cd chn
python3 manage.py runserver IP:80
And that is it! How i can do all this process to run in the background?
PS. The server is running on Linux/Ubuntu14.0 i think. If i put & at the end of each line, i will see them in my terminal, but i am afraid that it will stop all, when i close my mac/termina etc.
root#localhost:~# ps aux | grep 1373
root 30873 0.0 0.0 11724 680 pts/1 S+ 14:35 0:00 grep --color=auto 1373
root#localhost:~# ps aux | grep 30827
root 30875 0.0 0.0 11724 676 pts/1 S+ 14:36 0:00 grep --color=auto 30827
root#localhost:~# ps aux | grep 30835
root 30835 0.2 3.0 100644 31024 pts/0 S 14:33 0:00 python3 manage.py runserver IP:80
root 30877 0.0 0.0 11724 676 pts/1 S+ 14:36 0:00 grep --color=auto 30835
Thank you!
it worked with this command Nohup python3 manage.py runserver 5.83.45.64:80 &

Multiple apache and finding its ports

The following command
[cuser#vdev-b7-5461-4f3c-9d98-7fc3ec6 kafka]$ ps aux|grep apache
apache 3967 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3968 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3969 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3970 0.0 0.0 175412 3192 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3971 0.0 0.0 175276 2700 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3972 0.0 0.0 175276 2700 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3974 0.0 0.0 175412 3188 ? S 03:40 0:00 /usr/sbin/httpd -k start
apache 3975 0.0 0.0 175276 2696 ? S 03:40 0:00 /usr/sbin/httpd -k start
clduser 9566 0.0 0.0 103244 844 pts/1 S+ 16:41 0:00 grep apache
There are multiple apache process running in my machine. Is there a way for me to determine the files/directory each of these process uses to run it?
Also, would like to know the ports that they are using?
[user#vdev-37-5461-4f3c-9d98-7af28dfc3ec6 kafka]$ netstat -tulpn|grep 80
(No info could be read for "-p": geteuid()=500 but you should be root.)
tcp 0 0 :::80 :::* LISTEN -
This above command shows port 80 is being used but I want to know what process is using it?
[duser#vpsq-dev-4ac0b737-5461-4f3c-9d98-7af28dfc3ec6 kafka]$ find / -iname apache 2>/dev/null
/opt/logstash/vendor/bundle/jruby/1.9/gems/jruby-kafka-1.4.0-java/lib/org/apache
/opt/logstash/vendor/bundle/jruby/1.9/gems/logstash-output-elasticsearch-0.1.18-java/lib/org/apache
/opt/logstash/vendor/bundle/jruby/1.9/gems/jruby-kafka-1.1.2-java/lib/org/apache
/home/duser/logstash-1.5.0.rc2/vendor/bundle/jruby/1.9/gems/logstash-output-elasticsearch-0.1.18-java/lib/org/apache
/home/duser/logstash-1.5.0.rc2/vendor/bundle/jruby/1.9/gems/jruby-kafka-1.1.2-java/lib/org/apache

Can I delete [php] <defunct> processes

I made a PHP script which reads some data and starts a new process with pctnl_fork to do some work with the data. When the child processes are finished they stay in as process. ps aux shows me a list of processes like
demo 32229 0.0 0.0 0 0 pts/0 Z 12:23 0:00 [php] <defunct>
demo 32251 0.0 0.0 0 0 pts/0 Z 11:50 0:00 [php] <defunct>
demo 32284 0.0 0.0 0 0 pts/0 Z 11:50 0:00 [php] <defunct>
demo 32298 0.0 0.0 0 0 pts/0 Z 12:56 0:00 [php] <defunct>
demo 32303 0.0 0.0 0 0 pts/0 Z 11:50 0:00 [php] <defunct>
demo 32316 0.0 0.0 0 0 pts/0 Z 12:23 0:00 [php] <defunct>
Can I safely kill this processes as the parent process is still creating new processes to do some work? I know I should probably start the command piping to stderr (according to this topic Insane crond behavior. keeps making defunct bash processes now it is too late.
The parent process is running in the background.
After doing some research, it appears you'll have to kill the parent process for these defunct child processes to go away.
The most pertinent quote from the link says "You cannot kill a defunct process (a.k.a zombie) as it is already dead."
So as U said,
a command in your PHP, like
$a;
pcntl_waitpid($child_pid, $a, WNOHANG|WUNTRACED);
will do the job.
to me works, just fine !

How to see a terminal output from a previously closed terminal

I connect to a remote server using SSH
I was compiling using cmake and then make, it's not common to have a progress percentage in compilation process, but this time it has. I was watching the compilation process until my internet connection failed, so puTTY closed the session and I had to connect again to my server. I though that all the progress was lost, but i first make sure by watching the processes list by ps aux command, and I noticed that the processes related to the compilation are still running:
1160 tty1 Ss+ 0:00 /sbin/mingetty tty1
2265 ? Ss 0:00 sshd: root#pts/1
2269 pts/1 Ss 0:00 -bash
2353 pts/1 S+ 0:00 make
2356 pts/1 S+ 0:00 make -f CMakeFiles/Makefile2 all
2952 ? S 0:00 pickup -l -t fifo -u
3085 ? Ss 0:00 sshd: root#pts/0
3089 pts/0 Ss 0:00 -bash
3500 pts/1 S+ 0:01 make -f src/compiler/CMakeFiles/hphp_analysis.dir/bui
3509 pts/1 S+ 0:00 /bin/sh -c cd /root/hiphop/hiphop-php/src/compiler &&
3510 pts/1 S+ 0:00 /usr/bin/g++44 -DNO_JEMALLOC=1 -DNO_TCMALLOC=1 -D_GNU
3511 pts/1 R+ 0:03 /usr/libexec/gcc/x86_64-redhat-linux6E/4.4.4/cc1plus
3512 pts/0 R+ 0:00 ps ax
I would like to know if is possible to watch the current progress of the compilation by watching the previously closed terminal output. Something similar like 'cat /dev/vcsa1' or something
As per the comment above, you should have used screen.
As it is, you could try to peek at the file descriptors used by sshd and the shell that you started, but I don't think this will get you very far.

How to find the real owner of a process after su

We have a convention whereby developers get into a server with their own username, and then sudo su - django where django is the user our apps run under.
I need to find out which developer is running a script as django. With ps faux :
root 26438 0.0 0.0 90152 3320 ? Ss 10:38 0:00 \_ sshd: fred [priv]
fred 26444 0.0 0.0 90152 1852 ? S 10:38 0:00 | \_ sshd: fred#pts/0
fred 26445 0.0 0.0 66052 1560 pts/0 Ss 10:38 0:00 | \_ -bash
root 27923 0.0 0.0 101052 1336 pts/0 S 10:46 0:00 | \_ su - django
django 27924 0.0 0.0 66188 1752 pts/0 S 10:46 0:00 | \_ - bash
django 31760 0.0 0.5 227028 42320 pts/0 S+ 11:10 0:01 | \_ python target_script.py
I can easily see what fred is up to. However I need to write a script to act on this info, and I can find no way to pull out "fred" and "target_script.py" in one line with ps ... euser,ruser,suser,fuser all say "django." Will I need to fumble through this ps faux output to get the info I need?
I found this old post when trying to find the same basic information. The easiest way I found was to use the "loginuid" file under /proc/[pid]. For example:
cat /proc/${processid}/loginuid
Sorry for resurrecting such and old post, but maybe someone will find it useful.
You used su - django. The " - " will make the new shell a login shell (see manpage of su), which let the child process forget its parent uids. That's why euser,ruser,suser,fuser all say "django".
So yes, you may have to fumble through the parent process id, or through "ps faux".

Resources