Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-28-2004, 12:56 AM   #1
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, 01:11 AM   #2
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, 02:34 AM   #3
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, 08:48 AM   #4
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, 11:46 AM   #5
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 11:50 AM.


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 02:44 PM
Way to automatically restart a program? AlexV Linux - General 1 04-13-2005 06:23 PM
Key bindings program (custom pasting, program execution, etc.) jrdioko Linux - Software 2 02-05-2005 10:09 PM
Gtk-Warning but program still works... I close konsole, program closes Laptop2250 Linux - Software 2 11-15-2003 12:18 AM
Viewing program messages when program isn't run from command line? Locura Linux - Software 1 09-27-2003 09:19 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:57 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration