LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How To List The Process Running In A Server? (https://www.linuxquestions.org/questions/programming-9/how-to-list-the-process-running-in-a-server-137708/)

mphreddy 01-23-2004 01:49 AM

How To List The Process Running In A Server?
 
:confused:

I USE SOLARIS AND I HAVE USER PROCESS WHICH USES BASH SHELL,
AND WHEN EVER I TRY TO FIND OUT THE PROCESS ID THERE ARE MORE THAN THREE PROCESS RUNNING OF SAME TYPE
SO HOW TO DIFFERENCIATE BEETWEEN MY PROCESS AND OTHERS
I USE THE COMMAN "ps -l -u username"

FOR EXAMPLE :::


CONSIDER THIS OUTPUT OF MY SERVER:::

bash-2.03$ ps -l -u cfs
F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD
8 S 103 22124 21909 0 51 20 ? 132 ? pts/2 0:00 sh
8 S 103 22300 22114 0 51 20 ? 312 ? pts/7 0:00 bash
8 S 103 22114 22099 0 51 20 ? 132 ? pts/7 0:00 sh
8 S 103 20432 1 0 51 20 ? 315 ? ? 0:00 bash
8 S 103 22297 22124 0 51 20 ? 312 ? pts/2 0:00 bash
8 O 103 22309 22297 22 99 20 ? 312 pts/2 0:12 bash
bash-2.03$

now my process which is running is using bash shell , now how to diferenciate this process from others

which option with ps will work to solve this problem, i want this output to use in shell script and grep the PID and want to kill that process so what to do to solve this problem.
by trial and error i tried to kill all the three bash process running and ended up in killing other process,

thanks in advance for any info regarding this matter

with regard,
phani.
:confused:

itsme86 01-23-2004 02:25 AM

It's a very simple program to write:

Code:

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>

int main(void)
{
  printf("%d\n", getppid());
  return 0;
}

And when I run it:
root@dreams:~# ./getpid
24744

getppid() returns the PID of the parent process, which would be the shell. I double-checked to make sure that it works and, sure enough, it does. :)

root@dreams:~# w
12:17am up 28 days, 1:32, 3 users, load average: 0.14, 0.14, 0.16
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 - 20Jun03 28days 0.08s 0.08s -bash
root pts/0 itsme.tinymaze.c 12:15am 0.00s 0.09s 0.03s w
root@dreams:~# whoami
root
root@dreams:~# ps auxw | grep pts/0 | grep bash
root 24744 0.0 0.1 2020 1224 pts/0 S 00:15 0:00 -bash
root 24789 0.0 0.0 1328 452 pts/0 S 00:20 0:00 grep bash
root@dreams:~#

Obviously my TTY is the one that shows up at 0s idle in the 'w' output. Not to mention that it says I'm executing the 'w' command in the last column ;))


All times are GMT -5. The time now is 10:21 AM.