LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-29-2016, 09:21 AM   #16
malati desai
LQ Newbie
 
Registered: Sep 2016
Posts: 6

Original Poster
Rep: Reputation: Disabled

yah..I got your point..and I am working on it..
but I have some more questions in my mind..

1. waitpid waits for processes which are in parent-child relationship.
but other than that ,can a process wait for any processes which are
not in parent-child relationship?
Can process wait for any process?How to do that?

2.suppose I have pid of X process?
how to get all child processes of that X process..even if X process get exited ,how to get information (like pid) of its child processes..?
 
Old 09-29-2016, 09:27 AM   #17
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 8,104

Rep: Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267Reputation: 2267
1. you can use pgrep to check if a process was running.
2. you can use pstree to get process tree.
 
Old 09-29-2016, 01:38 PM   #18
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,599

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Quote:
Originally Posted by malati desai View Post
yah..I got your point..and I am working on it..
but I have some more questions in my mind..

1. waitpid waits for processes which are in parent-child relationship.
but other than that ,can a process wait for any processes which are
not in parent-child relationship?
Can process wait for any process?How to do that?
Nope. waitpid is for waiting for one out of many child processes. If you supply an arbitrary pid you will get an ECHILD error return if the supplied pid is not a child of the process using the waitpid system call.

That is why processes are reparented - init cannot receive any signals from any process other than its direct children. Reparenting allows those signals (specifically SIGCHLD) to be received.
Quote:
2.suppose I have pid of X process?
how to get all child processes of that X process..even if X process get exited ,how to get information (like pid) of its child processes..?
You don't. While the X process exists it is possible to search all processes that exist that have the X process as its parent - but once X exits, all child processes get reparented - by default, the parent becomes init. The problem is that such searches are asynchronous which permits losing references... pstree is an attempt to capture a snapshot of the process table (it isn't perfect as it is also asynchronous, but does try to reduce the window for failures) then sorts the data to create the process tree.

An example of when this fails is during fork bombs. It is also why you have trouble killing them. It is possible - but you have to make the priority of the process doing the search higher than any other process, AND never introduce a wait (which destroys the snapshot). The easiest way I found to stop a fork bomb has been to reduce the priority of all pids running the fork bomb. It took me 10 to 15 tries before the new pids running the fork bomb were all at a low priority (fortunately for me, I wasn't on a cluster at the time). THEN it was possible to kill them faster than they could spawn. (Even so - it is still possible for them to get away from you, but a "killall -u" on the users login eventually nails them all. It also helps to have some large memory CPU bound jobs to help force them into delays).

It is for this reason that the prctl system call was extended to setting what pid would be designated to be used when reparenting. This is the ONLY way that can sucessfully accomplish what you want.
 
  


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
Process Monitoring scottjsn SUSE / openSUSE 1 06-30-2012 02:33 PM
[SOLVED] Need help about monitoring process memory koshihaku Linux - Server 8 08-11-2010 07:39 AM
Monitoring a single process manoj.linux Linux - Enterprise 1 07-01-2009 01:26 AM
Process Monitoring arb Linux - Newbie 1 09-15-2003 09:35 AM
Process monitoring arb Linux - General 3 09-15-2003 04:29 AM


All times are GMT -5. The time now is 06:27 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration