LinuxQuestions.org
Help answer threads with 0 replies.
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 01-14-2005, 08:54 PM   #1
iclinux
Member
 
Registered: Dec 2004
Posts: 69

Rep: Reputation: 15
process monitor


I have to implement a program A that can prevent process B from being killed. And I can kill B with A by passing A some command...
BTW, Both A and B are background application.

I don't know how to do it.

Regards.
 
Old 01-14-2005, 08:58 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
What do you mean by program a preventing process b from being killed? Do you mean that program a is going to grab a semiphore that program b needs to have to exit (or something along these lines) or do you mean that program a is suppose to catch all the signals designated for program b so that no outsiders can pass a SIGKILL into program b?
 
Old 01-14-2005, 09:16 PM   #3
iclinux
Member
 
Registered: Dec 2004
Posts: 69

Original Poster
Rep: Reputation: 15
jtshaw,
thank you.

Sorry for my unclear meaning.

It's not so complicated. What I mean is that A is a monitor that queries B's status. If B has been killed illegally, A start B again.
And I can kill A with A by passing A somm command...

Regards
 
Old 01-14-2005, 09:26 PM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Ahh... ok, I get it.

What I would do is create a little program that has two threads... one which checks for use input on the command line (like a Q for quit or something) and one that checks a particular pid (perhaps that is passed in on the command line when the program is envoked) and checks to make sure it is still running.

You can check to see if a process pid is still running by seeing if it's directory still exists in /proc. The first time you check it you would want to save the value of /proc/<pid>/cmdline as well as the value of /proc/pid/cwd. This will tell you both the directory the pid was run from as well as the cmdline used to run it. You could then fork and exec to restart the program if it wasn't running anymore.
 
Old 01-14-2005, 09:28 PM   #5
iclinux
Member
 
Registered: Dec 2004
Posts: 69

Original Poster
Rep: Reputation: 15
The probelm is this: I don't know how to passing command to a background application.
Any method?
 
Old 01-14-2005, 09:30 PM   #6
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
It create a pipe (man 2 pipe) if I wanted to be able to pass information into a backgrounded process.
 
Old 01-14-2005, 09:35 PM   #7
iclinux
Member
 
Registered: Dec 2004
Posts: 69

Original Poster
Rep: Reputation: 15
jtshaw,

thanks a lot.

I'll try it, thank you!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Process monitor $@ya Programming 5 09-15-2005 11:57 AM
can inetd monitor process? iclinux Linux - Newbie 0 01-27-2005 06:49 PM
monitor process iclinux Programming 3 01-16-2005 02:00 PM
Process monitor in program ... joda Linux - Networking 1 06-10-2004 01:22 PM
How do I monitor a process? mad_ady Linux - General 5 11-07-2003 09:15 AM

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

All times are GMT -5. The time now is 10:54 PM.

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