LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-22-2010, 10:29 AM   #1
shva
Member
 
Registered: Feb 2009
Distribution: Fedora, Arch, Debian, Ubuntu
Posts: 56

Rep: Reputation: 15
How to distinguish different processes of the same program


First I create a named pipe at /tmp/.pipe by
Code:
mkfifo /tmp/.pipe
which is then used in a shell script called A.sh like this

Code:
#!/bin/bash
cat /tmp/.pipe &

myprogram  # some CLI program
If now I run this script in two different terminal sessions, and then do

Code:
ps -ef | grep "A.sh"
ps -ef | grep "cat /tmp/.pipe"
ps -ef | grep "myprogram"
I will get two different pids for script A.sh. Same to myprogram. My question is how to know which "cat /tmp/.pipe/" (or "myprogram") is initiated by which "A.sh" script? Thanks.
 
Old 05-22-2010, 02:35 PM   #2
fuubar2003
Member
 
Registered: May 2004
Location: Orlando, Florida
Distribution: SLES10/11, RH4/5 svrs, Fedora, Debian/Ubuntu/Mint; FreeBSD/OpenBSD
Posts: 63

Rep: Reputation: 26
ps -efH

# man ps ...check out the '-H' switch. Like:

Code:
# ps -efH
Example output:
Code:
root     32549  4423  0 15:04 ?        00:00:00     sshd: root@pts/0                                   
root     32552 32549  0 15:04 pts/0    00:00:00       -bash
root     32725 32552  0 15:28 pts/0    00:00:00         ps -efH
Or use '--forest' (same as -H but with lines illustrating hierarchy):

Code:
# ps -ef --forest

root     32549  4423  0 15:04 ?        00:00:00  \_ sshd: root@pts/0                                   
root     32552 32549  0 15:04 pts/0    00:00:00      \_ -bash
root     32762 32552  0 15:34 pts/0    00:00:00          \_ ps -ef --forest
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Distinguish Terminals Eilya Programming 12 09-22-2008 02:35 AM
Distinguish from the contents of a file which are the processes and print them jianelisj Linux - Newbie 4 03-19-2008 09:24 AM
Distinguish From The A File Contents Which The Processes Are jianelisj Linux - Newbie 1 03-19-2008 01:23 AM
Distinguish from the contents of a file which are the processes (NEWTHREAD) jianelisj Linux - Newbie 1 03-18-2008 02:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:40 AM.

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