Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for a valid pid in C, using Linux 2

Status
Not open for further replies.

alphadave

Programmer
Nov 1, 2005
2
CA
Hi, I'm trying to write a program that sends a signal from one process to another in C using the gedit program in linux. The only problem i've been having is that i cannot seem to be able to check for a valid pid so as to display an error message if a valid pid wasn't used. Any help is greatly appreciated.
 
You could check for the existance of a directory with the name of your pid in the "/proc" directory.
For each running process the kernel creates a directory with the pid as the directory name in "/proc". Inside that directory are a number of files giving details about the process. Your only interest would be to validate the pid and so simply checking for the directory name would suffice.
For example, if the pid is "54321" then look for a directory called "/proc/54321". If it exists then you have a valid pid, if not, you don't.

Ok?


Trojan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top