- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: ps command
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2001 06:15 AM
тАО07-12-2001 06:15 AM
What system calls does the ps command use to get the process information?
Kapil
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2001 06:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2001 06:20 AM
тАО07-12-2001 06:20 AM
Re: ps command
ps -ef |grep "program name"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2001 06:28 AM
тАО07-12-2001 06:28 AM
Re: ps command
Robin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2001 06:57 AM
тАО07-12-2001 06:57 AM
Re: ps command
These may help:-
ps -ef|sort ----- output sorted
ps -ef|grep
HTH
Paula
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2001 12:13 PM
тАО07-12-2001 12:13 PM
Re: ps command
I removes the grep from the list. The only problem I ran into is if you are looking for processes with grep in them.
alias -x px='ps -aef|grep -v grep | grep '
I put it in my .profile and I always have it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2001 05:09 PM
тАО07-12-2001 05:09 PM
Re: ps command
UNIX95= ps -C prog-name
This is much more efficient than grep'ing through the entire ps list and removing anything with grep. In fact it is the only way to accurately find all copies of grep.
NOTE: Counting the 'true' instances of any program is quite difficult to do accurately. The name of a program (the -C option) comes from the basename of the file containing the program. Any user could create a program called syncer (for instance) and other than the owner's name, it would be difficult to determine just what this program might be. The full pathname of a program is shown in ps only if the program was started that way (another good reason for all root scripts to use full pathnames).
Note also that the line: UNIX95= ps ... is not a typo. The UNIX95= is a quick way to TEMPORARILY assign the env variable UNIX95 for just the duration of the ps command. DON'T do something like:
export UNIX95=
ps -C prog-name
as many system programs and libraries will behave differently (ie, XPG4 behavior) with UNIX95 set. XPG4 also allows process hierarchies to be seen with the -H option.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-12-2001 05:12 PM
тАО07-12-2001 05:12 PM
Re: ps command
ps uses pstat_getproc() to do the major portion of its work. If I were doing it in c I think I would build up a command string and then call popen(). Something like this:
char s_cmd[1024];
char *target_process = "my_process";
FILE *f = NULL;
(void) sprintf(s_cmd,"ps -e | grep %s | grep -v grep",target_process);
f = popen(s_cmd,"r");
if (f != NULL)
{
char *p = NULL,s[512];
int knt = 0;
p = fgets(s,sizeof(s),f);
while (p != NULL)
{
++knt;
.....
p = fgets(s,sizeof(s),f);
}
(void) pclose(f);
(void) printf("%d instances of %s found\n",
knt,target_process);
}
This should be close to what you are looking for, Clay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2001 07:08 AM
тАО07-14-2001 07:08 AM
Re: ps command
That is exactly what I was looking for.
Thanks.
Hi John, Paula, Eric, Bill
Well, actually I wanted to find it out through a program without using the system function to invoke the ps command.
Thanks anyway.
Hi Robin,
I'll check it out.
Thanks.
Hi Clay,
The command pstat_getproc is what I was looking for.
Thanks.
Would the procedure that you mentioned be faster than using the pstat_getproc system call?
Just another clarification.
From the manual page for pstat I understand that when we want to use a shortcut i.e. to get info about a single process, the parameter index should refer to the pid of the process. But otherwise index should not refer to the pid of the process. Then what does index refer to in cases other than the shortcut?
Kapil