• C

information about a process?

I start a fork a new process in my program with execl and I get this process id. Is there a way for me to check and see later in my original program if this process is still running and to get the user id of this process.

LVL 2
joele23Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

joele23Author Commented:
hmm..must be tougher than I thought
0
anovickisCommented:
The answer depends on the system you run it on - perhaps you should elucidate.
0
mnashadkaCommented:
On UNIX/Linux you can use waitpid with the WNOHANG parameter (so that you don't block until it does exit).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Firewall Management 201 with Professor Wool

In this whiteboard video, Professor Wool highlights the challenges, benefits and trade-offs of utilizing zero-touch automation for security policy change management. Watch and Learn!

joele23Author Commented:
mnashadka

I dont quite get it. How will this tell me if the process is still running and the user id of this process?
0
mnashadkaCommented:
If waitpid returns the process id, that means that there's a status.  There's also a WIFEXITED macro on some systems that will help you tell if the process exited.
Alternatively, each system has it's own calls.  For instance, on Linux you could check to see if there's a directory named /proc/<process id> using access().
0
joele23Author Commented:
this still doenst tell me the user id though. I would think there had to pe a better way.
0
joele23Author Commented:
hmm..still no complete answer so pints going up
0
joele23Author Commented:
my typing skills suck sorry for typos
0
mnashadkaCommented:
getuid will get the int user id for the calling process.  Unless the process explicitly calls setuid, the child will have the same user id.
0
joele23Author Commented:
Ok,
but how do I know for sure that when I call waitpid that the process hasnt exited and a different process is running with the same pid. Is there a way to extract the process anme form this too?
0
joele23Author Commented:
by the way Im going to give you the pints I just want to make sure this all works
0
mnashadkaCommented:
waitpid will only work with child processes of the current process.
0
joele23Author Commented:
I still think thers a better way but this will  have to work.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.