# checking process existed

**URL:** <https://community.unix.com/t/checking-process-existed/186515>\
**Category:** HP-UX\
**Created:** [February 22, 2008, 10:03pm UTC](https://community.unix.com/t/checking-process-existed/186515 "2008-02-22T22:03:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frank2004](https://community.unix.com/letter_avatar/frank2004/32/5_5575768a8748004e209b776fc1b2916d.png) [@Frank2004](https://community.unix.com/u/Frank2004)\
**Post date:** [February 22, 2008, 10:03pm UTC](https://community.unix.com/t/checking-process-existed/186515/1 "2008-02-22T22:03:18Z")

</div>

On HP-UX, in application, if the process id has been get with the getpid() and sotred in database, then other monitor process want to check it if the process is existed, are there any system function can do it? I do not want to use the shell script, because it should use popen function to excuted and get the return, popen manupulate the pipe from process, it sometimes cause much I/O.

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [February 23, 2008, 7:11am UTC](https://community.unix.com/t/checking-process-existed/186515/2 "2008-02-23T07:11:34Z")

</div>

try man utmp or man wtmp.

The files record system activity, the man pages document calls to read the files directly.  
No popen needed.

---

<div class="post-metadata">

**Author:** ![Frank2004](https://community.unix.com/letter_avatar/frank2004/32/5_5575768a8748004e209b776fc1b2916d.png) [@Frank2004](https://community.unix.com/u/Frank2004)\
**Post date:** [February 25, 2008, 3:00am UTC](https://community.unix.com/t/checking-process-existed/186515/3 "2008-02-25T03:00:55Z")

</div>

Thanks, I'll try it.  
Here is another question:  
On HP-UX, how the file with the # character at the beginning generate and how to avod it?

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [February 25, 2008, 5:48am UTC](https://community.unix.com/t/checking-process-existed/186515/4 "2008-02-25T05:48:37Z")

</div>

Which file are you talking about? Can you give an example?

---

<div class="post-metadata">

**Author:** ![Frank2004](https://community.unix.com/letter_avatar/frank2004/32/5_5575768a8748004e209b776fc1b2916d.png) [@Frank2004](https://community.unix.com/u/Frank2004)\
**Post date:** [February 25, 2008, 9:33pm UTC](https://community.unix.com/t/checking-process-existed/186515/5 "2008-02-25T21:33:34Z")

</div>

The filename preceded with pound sign (#), such as:  
#hosts,#ntp.conf, #myprog, etc.

Once the opendir() or readdir() encounters the above format filename, the operation exit and can not look through the directory normmally. we want to void it.

---

<div class="post-metadata">

**Author:** ![jim\_mcnamara](https://community.unix.com/letter_avatar/jim_mcnamara/32/5_5575768a8748004e209b776fc1b2916d.png) [@jim\_mcnamara](https://community.unix.com/u/jim_mcnamara)\
**Post date:** [February 26, 2008, 10:18am UTC](https://community.unix.com/t/checking-process-existed/186515/6 "2008-02-26T10:18:37Z")

</div>

You can use ftw() or nftw(). Those require you to define a callback function that decides whether or not to continue.

I also don't see why readdir would exit, do you check return codes from opendir() and readdir() when this occurs? If you are using system() to do something, the shell being run in the system call will treat the '#' as a comment, rather than a file name.
