Vimzy
Vimzy

Reputation: 1965

Linux Command Outputs Terminated Processes

I'm working in C and using the following code to execute the ps linux command:

char *const parmList[] = {"ps","-o","pid","-g",processGroupID,NULL};
execvp(parmList[0], parmList);

The problem is that it prints all the processes from the group including ones that have been terminated. I need to make sure that the group processes that have NOT been terminated are the only ones shown. Is there a way to do this?

Upvotes: 1

Views: 994

Answers (2)

Dilip Kumar
Dilip Kumar

Reputation: 1746

ps command display's the list of active processes of that current tty terminal.

ps - axrgo pid or ps -axro pid -g

ps has an simple process selection option.

-a -------> Select all processes except both session leaders and processes not associated with a terminal. i.e includes all active terminals

-e -------> Includes all processes.

-g -------> Select by session OR by effective group name.

-r -------> Restrict the selection to only running processes.

-x -------> option causes ps to list all processes owned by you (same EUID as ps), or to list all processes when used together with the a option.

Upvotes: 1

Davislor
Davislor

Reputation: 15134

Add the a x r options to get only running processes.

Upvotes: 0

Related Questions