LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-23-2004, 01:49 AM   #1
mphreddy
LQ Newbie
 
Registered: Oct 2003
Posts: 7

Rep: Reputation: 0
Question How To List The Process Running In A Server?




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.
 
Old 01-23-2004, 02:25 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
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 )
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to list the process using most memory adoyee Linux - Newbie 3 09-06-2012 03:11 AM
User "list" running process "python" TroelsSmit Linux - Newbie 2 02-22-2005 04:55 AM
Running process sonu1082 Linux - Software 2 11-25-2004 05:32 AM
Multiple 'mozilla-bin' in process list.. Why? orgee Linux - Software 2 09-29-2004 07:38 PM
Process not running LinuxRam Linux - Newbie 4 09-09-2004 12:45 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:25 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration