LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-18-2007, 04:30 AM   #1
clalfa
LQ Newbie
 
Registered: Jul 2007
Posts: 7

Rep: Reputation: 0
Find out whether a process is alive


Hi all,
I need to find out whether a process is alive or it is killed (or zombie), and I would like to know if there is a C function which I could call to get this information. Note that the process I need to check is not a child process of the one which has to "investigate".

Do you know if such a function exists?

Thank you in advance
 
Old 07-18-2007, 04:45 AM   #2
munna_dude
Member
 
Registered: Dec 2006
Posts: 362

Rep: Reputation: 30
Quote:
Originally Posted by clalfa
Hi all,
I need to find out whether a process is alive or it is killed (or zombie), and I would like to know if there is a C function which I could call to get this information. Note that the process I need to check is not a child process of the one which has to "investigate".

Do you know if such a function exists?

Thank you in advance
hi
this may be helpfull to you
Quote:
ps -A
or
ps -A | grep "processname"
or
ps -fe | grep "processname"
cheers
munna
 
Old 07-18-2007, 04:52 AM   #3
clalfa
LQ Newbie
 
Registered: Jul 2007
Posts: 7

Original Poster
Rep: Reputation: 0
The problem is that ps is a shell command...
I need a function which I could call in a C program. Basically, I have the pid of a process and would like to pass that value to a function and get back "alive" or "error" or something like that.
I think I could use a non-blocking waitpid, but that only works if the process you want to find out about is a child of the calling process...
 
Old 07-18-2007, 05:41 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
kill -0 pid works in shell

so maybe using sigsend too?
 
Old 07-18-2007, 06:13 AM   #5
clalfa
LQ Newbie
 
Registered: Jul 2007
Posts: 7

Original Poster
Rep: Reputation: 0
THANK YOU!!!! that's what I was looking for!!

Code:
if ( sigsend (P_PID, n1_id, 0) == 0 )
    printf ("Process %d is alive!!\n", n1_id);
I think this should work...if only the linker could find sigsend!!!
This is what it says:
Code:
:main.c:(.text+0x2ed): undefined reference to `sigsend'
I wonder if I have to include some linking options when launching gcc
(as I do with curses.h: -lncurses). If this helps you, I am using Ubuntu 6.06.1 ....

Please help me!! This is quite an urgent thing...
 
Old 07-18-2007, 06:23 AM   #6
munna_dude
Member
 
Registered: Dec 2006
Posts: 362

Rep: Reputation: 30
Quote:
Originally Posted by clalfa
THANK YOU!!!! that's what I was looking for!!

Code:
if ( sigsend (P_PID, n1_id, 0) == 0 )
    printf ("Process %d is alive!!\n", n1_id);
I think this should work...if only the linker could find sigsend!!!
This is what it says:
Code:
:main.c:(.text+0x2ed): undefined reference to `sigsend'
I wonder if I have to include some linking options when launching gcc
(as I do with curses.h: -lncurses). If this helps you, I am using Ubuntu 6.06.1 ....

Please help me!! This is quite an urgent thing...
mab be it is helpful
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sysexits.h>

cheers
munna
 
Old 07-18-2007, 07:32 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
#include <signal.h>
 
Old 07-18-2007, 08:02 AM   #8
clalfa
LQ Newbie
 
Registered: Jul 2007
Posts: 7

Original Poster
Rep: Reputation: 0
I had already included signal.h, but it doesn't work. That's the strange thing: even if signal.h exists and is in the proper place, it seems that the linker can't find it.
The problem remains, but at least I've found another way of doing what I had to do...

Thank you anyhow for your interest
 
Old 07-18-2007, 10:36 AM   #9
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
Quote:
Originally Posted by clalfa
I had already included signal.h, but it doesn't work. That's the strange thing: even if signal.h exists and is in the proper place, it seems that the linker can't find it.
The problem remains, but at least I've found another way of doing what I had to do...

Thank you anyhow for your interest
and that other way is...
 
  


Reply



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
how to find per-process swap utilization? ananthbv Programming 1 11-02-2006 01:16 AM
How to check the child process alive ? stny Programming 2 10-16-2006 05:12 PM
How to find out whether a process is dead or alive from within a shell script file walwali Linux - Software 2 12-24-2005 01:39 PM
How to find a swapped out runnable process? slice Linux - General 0 09-29-2004 08:51 AM
How to find the pid to stop a process.... vous Linux - Networking 6 08-14-2003 04:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:27 AM.

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
Open Source Consulting | Domain Registration