spawning the same program


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users spawning the same program
# 1  
Old 08-10-2005
spawning the same program

We have a program (reader) that reads audio files in a real-time continuous stream from a sender program. If the reader gets weird we want the sender to be able to send one command that will stop the current reader and start a new one that will be able to continue reading in the files. The sender cannot access anything other than the reader (ie, it cannot run any commands on the server, etc). The reader runs on UNIX and is written in C++.

I've tried using system() to call a batch file that sleeps for a few second and then starts a new reader. It starts a new reader but the old one stays up. I've also tried exec(), which does replace the old reader with the new one but the new reader doesn't read the audio files; it just seems to sit out there doing nothing.

Is there a way to have a program basically kill itself and start a fresh version of itself that works?

Thank you.
# 2  
Old 08-10-2005
Rather than system, use exec to invoke the startup script.
# 3  
Old 08-11-2005
Using exec()

I had tried exec() and it did replace the current reader with a new reader but the new reader didn't work. It was running, but it didn't read the audio files and didn't respond to a remote shutdown like the first one can.

This is the command that I used:
execl("./Reader", (char *) NULL);

Am I missing something?

Thanks.
# 4  
Old 08-11-2005
What did you use in the system call that worked? Another thought is to go back to system() and exit() afterwards.
# 5  
Old 08-11-2005
Using system instead

I did try system() followed by exit() but the problem with using system() is that it will remain up until the program called in system() exits. So it follows this scenario using "ps -ef | grep Reader":
1) First startup - the first Reader is up
./Reader
2) Run system() followed by exit() - both Readers are up and the exit() isn't reached because it is waiting for the system() to complete
./Reader
./Reader
3) Second ./Reader exits and both are now gone since the first Reader continued and reached its own exit.

system() starts a child process. I really just want to kick off a new, separate process and exit the first process.
# 6  
Old 08-11-2005
system() run a command line to a shell. You can put an & at the end of any command line to background it. That works even with system.

You don't seem to be passing any args to script when you invoke it, so I'm not sure why exec isn't working. You did leave off argument 0 which is the name. I thought that was a trivial problem, but maybe it's important. So try it right.
execl("./reader", "reader", NULL);
All of this assumes that you have an executable shell script. Do you? What os are you using? What is the first line of the script?
# 7  
Old 08-11-2005
The operating system is:
SunOS grcs 5.8 Generic_108528-13 sun4u sparc SUNW,Ultra-5_10

This is the script that starts the program:
#!/usr/bin/ksh
export LD_LIBRARY_PATH=/usr/local/lib
export DLI_LOG_MSGS=DEBUG
export DLI_LOG_FILE_NAME=DLIMain.log
./Reader

I've tried calling the script:
rt = execl("./setenv1", "setenv1", (char *) NULL);
if (rt != 0)
printf("exec failure: %d\n", errno);

and I've tried calling the program directly:
rt = execl("./Reader", "Reader", (char *) NULL);
if (rt != 0)
printf("exec failure: %d\n", errno);

Neither works. The Reader is using a UDP socket to read the audio files from the sender. I don't know if that if affecting anything.

I don't know how to use & when calling exec() in C++ code.

Thanks for your help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Spawning a TTY shell

Hi there, I would like to understand the purpose of spawning a TTY shell? Does it mean that it will help to open up a new Windows on the current interactive shell such that when the session gets lost the other won't Any explanation will be helpful. (3 Replies)
Discussion started by: alvinoo
3 Replies

2. AIX

Multiple pconsole processes spawning indefinetly

Good night everyone, I've been trying to make AD authentication work with RBAC and I think I messed my test LPAR up. I've manually modified the /etc/security/user.roles file, adding a role to one of my AD users (who is not defined locally) and then runned setkst. It worked fine, but now I found... (3 Replies)
Discussion started by: Janpol
3 Replies

3. Shell Programming and Scripting

lost the $ prompt - am I spawning shells??

When trying to get the correct syntax to cron a script that creates a file with the date stamp as its output, sometimes I get these results: - from the command line, I may encounter an error that leaves me without the usual $ prompt. Am I in a new shell? I try to exit it with 'exit' or :q! and... (1 Reply)
Discussion started by: landog
1 Replies

4. UNIX for Advanced & Expert Users

Help! imapd is spawning multiple processes, all of a sudden, for no reason!

Hi All, I need some assistance, if possible... Our IMAP server has recently (as of 10:30 GMT today) started spawning multiple processes for no reason! This is causing the mail server's load average to increase continually until the whole machine grinds to a halt. Here is a typical... (0 Replies)
Discussion started by: fishsponge
0 Replies

5. UNIX for Advanced & Expert Users

Crontab spawning multiple at processes

Hi - I need help. My user crontab is spawning multiple at processes (and multiple mencoder program starts, that exit, then restart, repeatedly), locking up my system. For example I have this entry in my crontab: $ sudo crontab -u victoria -e * * * * * ~/recordings/pvr1 * * * * *... (10 Replies)
Discussion started by: gstuart
10 Replies

6. Shell Programming and Scripting

Spawning multiple threads in Unix

Hi, I need to spawn mutilpe threads , each invoking a different set of shell scripts, in parallel. What would be the best way to do that. Any sample script would greatly help. I am a novice at Unix so any help is much appreciated. Thanks (5 Replies)
Discussion started by: neeto
5 Replies

7. Programming

spawning multiple processes spread across two files

I want to spawn n child processes but have two different classes..with the foremost one forking/spawning the child process and the latter performing a function w/ the spawned processes. I can do this in one class with an if statement and the simple if((pid=fork())==0) //child process { ... (1 Reply)
Discussion started by: StrengthThaDon
1 Replies

8. Shell Programming and Scripting

Spawning a shell script

Hi there, I have a shell script which I need to run it from two different places on the same server, are there any specific rules I need to apply? What is the best practice to achieve this task. Regards (5 Replies)
Discussion started by: JimJim
5 Replies

9. Shell Programming and Scripting

Spawning new shells from the command line in OpenStep 4.2

Hi all, Im trying to figure out what the command would be to launch terminal windows from the command line in Open Step 4.2 . (looking for something similiar like /usr/bin/xterm or /usr/bin/dtterm etc) echo $TERM = vt100 echo $SHELL = /bin/csh Im combing over alot of OpenStep 4.2 and... (3 Replies)
Discussion started by: Rocketman8541
3 Replies

10. Solaris

spawning new shells using dtterm in Solaris 8

Hi all, First time poster here. Great forum. Im trying to spawn new shells and pass commands to the new shells in a solaris 8 environment utilizing dtterm and its option -e. I can successfully spawn a window utilizing the following code: /usr/dt/bin/dtterm -display <ip.address> & ... (4 Replies)
Discussion started by: Rocketman8541
4 Replies
Login or Register to Ask a Question