LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 02-05-2024, 12:01 AM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
executing a new program in the same process ID


it is easy enough to execute a new program image in the same process ID when running the execve() call in that same process. but i need to do something a bit different. i will have a process running program ABC which would be a binary image compiled and linked for Linux. after ABC ends, i want to run program XYZ in that very same process ID. but, program ABC has no code at its end to execute XYZ. changing the source code of ABC to do a re-compile is not an option because the source code is not available. i'd like to know if anyone has put together something that can accomplish this. my first thought is doing a dynamic loading of ABC in order to get control back at the end of ABC while still in the same process. i would think this needs to be in C. any ideas?

i know, many of you will wonder why i need to run XYZ in the same process. well i could work around it. but it would be a lot of automatically processing many output streams to fake process IDs, so i am looking at this as the simpler solution.
 
Old 02-05-2024, 12:32 AM   #2
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,593
Blog Entries: 19

Rep: Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455
What normally happens when a program exits is that the kernel notifies the parent process, which is then supposed to call wait() to "reap" the child and collect its last words. After that the kernel destroys the child process's task structure, so that process no longer exists. If the parent doesn't reap the child, it becomes a zombie and its task structure remains inside the kernel. What you want to do would be the equivalent of bringing a zombie back to life. I don't think the kernel would let you do that.
 
Old 02-05-2024, 01:08 AM   #3
Skaperen
Senior Member
 
Registered: May 2009
Location: center of singularity
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,684

Original Poster
Blog Entries: 31

Rep: Reputation: 176Reputation: 176
i agree that the kernel would not normally let me do this. but perhaps ptrace() provides a way.
 
Old 02-05-2024, 01:34 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,883

Rep: Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317Reputation: 7317
no. I don't think you really need it. What do you want to solve by that?
This is against the philosophy of this whole thing. A process cannot be replaced on the fly, the only way is if the process itself wanted to do so (using the mentioned exec function).
It is just bad design.
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Crontab not executing my shell script its executing standlaone atulkvtiwari Linux - Newbie 15 12-04-2018 06:25 AM
Problems executing perl script with inputs when executing under other perl scripts TheStr3ak5 Programming 4 04-22-2017 04:07 AM
Executing a c++ program from within a c++ program cyberfox007 Programming 1 02-03-2008 10:14 PM
How to find the process ID of process executing in the background akeneche Linux - Newbie 1 01-03-2008 10:08 AM
prevent users to run the same script at the same time, on the same machine pvpnguyen Programming 2 09-05-2007 08:52 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:44 AM.

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
Open Source Consulting | Domain Registration