LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-01-2006, 05:46 AM   #1
aravindtj
LQ Newbie
 
Registered: Jan 2005
Location: India
Posts: 4

Rep: Reputation: 0
Question Setting timeout for a process


Hi,

I want to start an external application as a process from my C++ application.
After some timeout value, that external application should be terminated.
I followed the following algorithm:

RunTill(myCommand, tillTime)
{
lock.initialize()
hdl = pthread_create(mythread, NULL, RunThread, (void*)this);
while(timeout)
{
if(lock.trylock())
{break;}
}

if(timedOut)
{
pthread_detach(mythread);
pthread_cancel(mythread);
}
lock.destroy();
}

RunThread()
{
lock.lock()
system(myCommand);//*****//
lock.unlock()
}

Now, this is working for me. But when I provide the muCommand as "perl myscript.pl", the command never expired even after the timeout period.

I thought of using system command, it creates the process [perl myscript.pl] as a independent process and doesn't have control of that.

Can you please give me any solution to solve this problem?

Thanks in advance.

Aravind
 
Old 09-01-2006, 05:53 AM   #2
debiant
Member
 
Registered: Jul 2006
Distribution: Source Mage 0.9.6
Posts: 196

Rep: Reputation: 30
http://www.shelldorado.com/scripts/cmds/timeout.txt
 
Old 09-01-2006, 06:12 AM   #3
aravindtj
LQ Newbie
 
Registered: Jan 2005
Location: India
Posts: 4

Original Poster
Rep: Reputation: 0
Question Setting timeout for a process Reply to Thread

Hi Debiant,

Thanks for the instant answer!
Can I do the same by using C++ coding itself?
Instead of using the shell script, I prefer to do the things in C++/C code.
How can I get the PID of the process [myapplication] started by system("myapplication")?

If it is not possible, what command [exec, spawn, etc] returns the PID of the created process?

Thanks in advance.

Aravind
 
Old 09-01-2006, 06:56 AM   #4
debiant
Member
 
Registered: Jul 2006
Distribution: Source Mage 0.9.6
Posts: 196

Rep: Reputation: 30
I'm sure you can and I apologize for not looking closer at your original example. I can't help you much on that end, and to be honest I just googled the script that I linked. I have to be off to work. But if you want your thread here to get the exposure it deserves, you should report your post to a mod and ask them to move it to the programming forum. There are some VERY knowledgable C/C++ programmers here that should definately be able to help you.

Sorry,
 
Old 09-05-2006, 03:06 AM   #5
aravindtj
LQ Newbie
 
Registered: Jan 2005
Location: India
Posts: 4

Original Poster
Rep: Reputation: 0
Thumbs up

Hi,

At last,

It is working for me.

I just made a mistake in timeout calculation and after correcting that, it is working for me.

I believe that the new thread created the system("..") process and terminating the thread will terminate all the processes created by that thread. So, it is working for me.

Any how, thanks for all your prompt replies,

Regards,
Aravind
 
  


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
Errors in setting up inter-process comm. for KDE. tommy12 SUSE / openSUSE 0 08-24-2006 05:50 PM
Setting GRUB default timeout duration Pax Digita Linux - Newbie 2 04-13-2006 03:21 PM
setting network start timeout at boot sayantam Linux - Networking 1 06-10-2004 05:20 AM
Setting eth0 timeout, Mandrake 9.2 on Inspiron 8200 83K5 Linux - Laptop and Netbook 0 02-04-2004 05:08 PM
Mandrake: Partitioning during installation and setting up boot process. OtakuMark Mandriva 2 02-02-2004 07:50 AM


All times are GMT -5. The time now is 08:36 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration