LinuxQuestions.org
Review your favorite Linux distribution.
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 09-27-2004, 11:56 PM   #1
sibtay
Member
 
Registered: Aug 2004
Location: U.S
Distribution: Ubuntu
Posts: 145

Rep: Reputation: 15
Restart a program


I want to give an option to users to restart my program. For example the program should terminate and then start again when user enters "restart".

How is this possible?
 
Old 09-28-2004, 12:11 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
'man exec'

It replaces the current running program with the new one (the same program of course in your situation).
 
Old 09-28-2004, 01:34 AM   #3
cppkid
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
Hi Sibtay! Tayyab here!
I think itsme86 is right, You can fork a new process make that process independent and then terminate your original process. And there can be another way is that write a shell script that starts a new copy of your process and kill the previous copy of your process. When you want to restart just execute your script using system() command and it will start a new copy and then will destroy your provious copy.
Wish you all the best.
 
Old 09-28-2004, 07:48 AM   #4
sibtay
Member
 
Registered: Aug 2004
Location: U.S
Distribution: Ubuntu
Posts: 145

Original Poster
Rep: Reputation: 15
How are you Tayyab ...and whats happening these days?

Ok i can start a new process of my program with system() call

Now i have to kill the previous process..

How can you get a process's process id?
 
Old 09-28-2004, 10:46 AM   #5
Ikebo
Member
 
Registered: Jun 2004
Location: Michigan, USA
Distribution: Ubuntu
Posts: 77

Rep: Reputation: 15
The call to system() will fork a new child process, if you then try to kill the parent process the child processes will be defunct.

Follow itsme86's advice, use exec() (or execlp() ). It will overwrite your current process with a new process image that you specify ( like system() ) without having to deal with any child and parent process overhead.

edit: I should proofread more frequently.

Last edited by Ikebo; 09-28-2004 at 10:50 AM.
 
  


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
Total recovery: Which program? ghost4linux, YaST2? Best drive imaging program? lagu2653 Linux - Software 1 06-20-2005 01:44 PM
Way to automatically restart a program? AlexV Linux - General 1 04-13-2005 05:23 PM
Key bindings program (custom pasting, program execution, etc.) jrdioko Linux - Software 2 02-05-2005 09:09 PM
Gtk-Warning but program still works... I close konsole, program closes Laptop2250 Linux - Software 2 11-14-2003 11:18 PM
Viewing program messages when program isn't run from command line? Locura Linux - Software 1 09-27-2003 08:19 AM

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

All times are GMT -5. The time now is 08:34 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