user15874403
user15874403

Reputation:

Linux how to check if parent process exists?

In linux we can access process parent like this:

current->parent

my question is how can we check if the parent still exists?

The reason is that I am implementing a loop that visits all ancestors of current process and want to know when to stop.

Upvotes: 1

Views: 408

Answers (1)

dbush
dbush

Reputation: 225437

When the parent of a particular process exits, the child is inherited by the init process.

So you can check if the parent process is running if getppid() returns a value other than 1.

Upvotes: 1

Related Questions