Problem in Child process
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Problem in Child process




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Problem in Child process  
seema_coma@yahoo.co.in


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-29-05 12:47 PM

Hi All I am new to unix programming. I have a
problem, I am using fork and in the child
process I am doing some what like this,

if ((pid = fork()) == 0) {
execvp(path, regdArgv);/*execute "my executable"*/
}

which will invoke an executable. But i just
want to do some thing like this,
if ((pid = fork()) == 0) {
if (/my executable is already running*/){
exit(0);
}
else{
execvp(path, regdArgv);
}

}

Can some body explain how to CHECK that executable
is already running ?

Thanks in Advance,
Seema Rao






[ Post a follow-up to this message ]



    Re: Problem in Child process  
Jordan Abel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-29-05 12:47 PM

On 2005-10-29, seema_coma@yahoo.co.in <seema_coma@yahoo.co.in> wrote:
> Hi All I am new to unix programming. I have a
> problem, I am using fork and in the child
> process I am doing some what like this,
>
> if ((pid = fork()) == 0) {
> execvp(path, regdArgv);/*execute "my executable"*/
>}
>
> which will invoke an executable. But i just
> want to do some thing like this,
> if ((pid = fork()) == 0) {
>     if (/my executable is already running*/){
>          exit(0);
>     }
>     else{
>         execvp(path, regdArgv);
>     }
>
>}
>
> Can some body explain how to CHECK that executable
> is already running ?
>
> Thanks in Advance,
> Seema Rao
>

Well, other than the obvious question of why you want to do this
[what if someone wants to run multiple instances of the program],
i'd suggest using a pidfile





[ Post a follow-up to this message ]



    Re: Problem in Child process  
seema_coma@yahoo.co.in


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-29-05 12:47 PM

I just want to stop running multiple instance of the program.Would you
please give me a hint on how to use pidfile






[ Post a follow-up to this message ]



    Re: Problem in Child process  
Jordan Abel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-29-05 12:47 PM

On 2005-10-29, seema_coma@yahoo.co.in <seema_coma@yahoo.co.in> wrote:
> I just want to stop running multiple instance of the program.Would you
> please give me a hint on how to use pidfile

Can you explain _why_ you want that?





[ Post a follow-up to this message ]



    Re: Problem in Child process  
seema_coma@yahoo.co.in


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-29-05 12:47 PM

Basically my executable again forks and executes a system wide daemon.
So if i run multiple instance of the code i am mentioning like,
linux_i32/somepad&;linux_i32/somepad&;linux_i32/somepad&
It will invoke multiple instances of daemon and even my Linux Box goes
out of memory and hangs. Thats why!!






[ Post a follow-up to this message ]



    Re: Problem in Child process  
Jordan Abel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-29-05 12:47 PM

NNTP-Posting-Host: tark-b-149.resnet.purdue.edu
X-Trace: mailhub227.itcs.purdue.edu 1130587043 31836 128.211.221.149 (29 Oct
 2005 11:57:23 GMT)
X-Complaints-To: news@purdue.edu
NNTP-Posting-Date: Sat, 29 Oct 2005 11:57:23 +0000 (UTC)
User-Agent: slrn/0.9.8.1 (FreeBSD)
Xref: number1.nntp.dca.giganews.com comp.unix.programmer:162197

On 2005-10-29, seema_coma@yahoo.co.in <seema_coma@yahoo.co.in> wrote:
> Basically my executable again forks and executes a system wide daemon.
> So if i run multiple instance of the code i am mentioning like,
> linux_i32/somepad&;linux_i32/somepad&;linux_i32/somepad&
> It will invoke multiple instances of daemon and even my Linux Box goes
> out of memory and hangs. Thats why!!

This should be handled from the initscript [shell script in
/etc/init.d or /etc/rc.d] that invokes your system daemon - not in a
binary executable.





[ Post a follow-up to this message ]



    Re: Problem in Child process  
seema_coma@yahoo.co.in


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-29-05 12:47 PM

We use this Daemon as System Daemon and some time Daemon for single
user. So how do I stop multiple instance in that case?






[ Post a follow-up to this message ]



    Re: Problem in Child process  
Jordan Abel


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-29-05 10:51 PM

On 2005-10-29, seema_coma@yahoo.co.in <seema_coma@yahoo.co.in> wrote:
> We use this Daemon as System Daemon and some time Daemon for single
> user. So how do I stop multiple instance in that case?

Redesign your program - what kind of daemon is it?





[ Post a follow-up to this message ]



    Re: Problem in Child process  
joe@invalid.address


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-29-05 10:51 PM

seema_coma@yahoo.co.in writes:

> Hi All I am new to unix programming. I have a
> problem, I am using fork and in the child
> process I am doing some what like this,
>
> if ((pid = fork()) == 0) {
> execvp(path, regdArgv);/*execute "my executable"*/
> }
>
> which will invoke an executable. But i just
> want to do some thing like this,
> if ((pid = fork()) == 0) {
>     if (/my executable is already running*/){
>          exit(0);
>     }
>     else{
>         execvp(path, regdArgv);
>     }
>
> }
>
> Can some body explain how to CHECK that executable
> is already running ?

Have the executable create a file somewhere (on a *local* file
system), and get a lock on it. It can simply be a zero length file,
the important thing is that it's locked.

When the program starts up, have it try to get a lock on the file. If
it can't get a lock, then an instance of the program is already
running.

Joe
--
Gort, klatu barada nikto





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 05:11 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register