473,785 Members | 2,460 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Linux having problems with execlp

175 New Member
I'm trying to write a program in C on Linux where the child processes get their process images replaced. I have in my code, a few child processes that I forked from a single parent process. I'm then attempting to replace their ( the child ) process images with separate executables. I have these executables written and placed in the directory.

My problem is when I'm using execlp. When it reaches execlp in my code, it does replace the process image and executes the new image ( for the first execlp it reaches ), BUT once it reaches the first execlp and is executing that code, it never gets past that point in the code. These processes should be running concurrently. Is there some trick to this. I've never used Linux before, and I'm pretty confused. Any help would be appreciated.

Expand|Select|Wrap|Line Numbers
  1. if ( j == 1 )
  2. {
  3.     execlp("./c2", "c2", (char *)0);
  4. }
  5. else if ( j == 2 )
  6. {
  7.     execlp("./c3", "c3", (char *)0);
  8. }
  9.  
here's the execlp part of my code. The j is a for loop, ( it goes well past 2 ). The "c2" and "c3" are names of the .exe's that replace these child process images. Once the j==1 is reached, it never gets passed it ... I want it to continue past it ... continue having that process running with it's new image, then the next process to start running alongside the previous one.
Feb 24 '08 #1
2 3255
sydneytroz
7 New Member
Where do you call fork()? It looks as though the process is replaced during iteration i=1 of your for loop, and that would be why nothing else happens. You might want to fork inside the if blocks.

Expand|Select|Wrap|Line Numbers
  1. if (j == 1) {
  2.     if (fork()) exec();
  3. } else if (j == 2) {
  4.     if (fork()) exec();
  5. } ... 
Feb 24 '08 #2
manontheedge
175 New Member
sidneytroz,

thank you very much for that, it fixed my problem perfectly. But, now with that working, I have a new question:

in my code, I'm creating these child processes, so I want to save each child's process ID in a variable, so that the parent process can later kill them, on an individual basis. If I create a tempory integer variable for each process and put the individual process ID in each of their own allotted variables, the value is erased by the time the parent process gets to look at the variable. Why is this happening? I would think the variable would hold it's value.
Feb 24 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
2216
by: Ranger West | last post by:
Hello there, Are there any out-of-the box handhelds that run Linux/Apache/MYSQL and PHP? Does Redhat, Suse, or Gentoo support any handhelds? I know the Zaurus comes close, but I've heard people have problems running LAMP applications on it. It would be cool to be able to run any LAMP application on sourceforge on a handheld computer.
4
10043
by: Paul Nilsson | last post by:
Hi, Does anyone know how to redirect text output when issuing a system or an execlp call? I have a GUI that insists on opening up a console whenever I give a system function call, and I would like to redirect the text output to a char buffer instead. Paul
3
3781
by: Mairhtin O'Feannag | last post by:
Hello, I have a new Linux RH 9.0 server, on which I'm trying to setup DB2. I did the RPM install of IBMJava2-JRE-1.4.1-2.0, which I got from the IBM site. All *APPEARED* to have worked fine. But ... rpm -aq IBMJava2-JRE- 1.4.1-2.0 shows no entry. A simple rpm -aq shows it as the last item in the list. <scratching head>. Now, when I got to the place I untarred DB2 v8.1 (/local4/db281/009 _ESE_LNX_32_NLV) and type ./db2setup, what...
23
3499
by: Rudolf Bargholz | last post by:
Hi, I have a ralatively simple SQL: select FK from TABLE where upper(A) like 'B%' and upper(C) like 'D%' We have DB2 UDB v7.1 FP 12 installed on Linux and on Windows 2003 On Linux using optimization level 5 as well as 9 and 0 the SQL uses 3'100'000'000 timerons !
57
3708
by: B.r.a.d.l.e.y | last post by:
A client has moved a back-end data file to a Linux machine instead of Windows. It now will only let one user log in at a time and gives some sort of "admin file not found" error. My first thought was permissions to create the LDB file but they swear this is correct. (read/write access for MDB & MDW files, read/write/create access in folder) Anyone come across a similar problem?
6
5336
by: Erik S. Bartul | last post by:
as i understand if, the first argument of execlp() is a null terminated string containing the path of the command which to be executed. the second argument is an array of pointers to null terminated strings, containing the arguments to be passed to said command, ending in a null pointer. my question is, what does the third argument do?
6
2824
by: rabidmonkey | last post by:
Hi all, I have written a server & child program both are working fine but when the server tries to execute the child program with the line execlp("child","child", parameter, NULL ); nothing happens it does not call it, yet if I test the above line by substituting child with a system binary like pwd or ls it calls it without trouble. I have used the command "chmod a+x child" to make child executable but still to run child manually at the...
6
2461
by: druidamix | last post by:
I'm trying to make a gui for an application, but it not run. i'm trying to send the output of execlp to pipe and read from his father. but i don't obtain results. Any advince? Thank you. This is the code:
8
2823
by: Okonita | last post by:
Hi all, I have gone through the process of installing DB2 UDBv9 Express-C in my local linux environment. I am used to having icon placed on my Desktop or taskbar for easy access to (db2cc) Control Center. After installation, how then can I get access to DB2? How can I place a desktop icon in linux for easy access to DB2? Also, I will like to know how I can make DB2 control center in my windows environment detect the recent DB2...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10147
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.