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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-14-2005, 08:54 PM
|
#1
|
Member
Registered: Dec 2004
Posts: 69
Rep:
|
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.
|
|
|
01-14-2005, 08:58 PM
|
#2
|
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Rep:
|
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?
|
|
|
01-14-2005, 09:16 PM
|
#3
|
Member
Registered: Dec 2004
Posts: 69
Original Poster
Rep:
|
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
|
|
|
01-14-2005, 09:26 PM
|
#4
|
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Rep:
|
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.
|
|
|
01-14-2005, 09:28 PM
|
#5
|
Member
Registered: Dec 2004
Posts: 69
Original Poster
Rep:
|
The probelm is this: I don't know how to passing command to a background application.
Any method?
|
|
|
01-14-2005, 09:30 PM
|
#6
|
Senior Member
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Rep:
|
It create a pipe (man 2 pipe) if I wanted to be able to pass information into a backgrounded process.
|
|
|
01-14-2005, 09:35 PM
|
#7
|
Member
Registered: Dec 2004
Posts: 69
Original Poster
Rep:
|
jtshaw,
thanks a lot.
I'll try it, thank you!
|
|
|
All times are GMT -5. The time now is 10:54 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|