problem using execl to start a tftp process


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers problem using execl to start a tftp process
# 1  
Old 02-01-2012
problem using execl to start a tftp process

Hi,
I'm very new to Linux but have been muddling my way through quite happily until recently.
I'm trying to write a program in C++ which starts a new process using the execl command. I am trying to run the tftp process as follows:
Code:
char ip_addr[] = "...";
 
if (execl("usr/bin/tftp", "tftp", "-4", ip_addr, "-c", "get", "myfile.txt", NULL) == -1)
{
   //ERROR!
}
else
{
   ...
}

Unfortunately, this is not working and the execl command returns -1.
I have tried the same program replacing the tftp with a simple command (ls) and it works fine.
I have also tried typing the tftp command into a terminal and that works fine (the file is transferred as I would expect)
Can anyone spot anything daft that I'm doing? Is there any way I can get more information as to why the execl command failed?
Many thanks in advance.
# 2  
Old 02-01-2012
execl does not start a new process. It completely replaces the current process. If it succeeds, your else clause won't ever run!

You are missing a /.

Code:
if (execl("/usr/bin/tftp", "tftp", "-4", ip_addr, "-c", "get", "myfile.txt", NULL) == -1)

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 02-01-2012
I knew it was going to be something daft like that I'd missed! Smilie
Thank you so much!

You are right about my else statement of course. I have used fork to get back to my parent process elsewhere in the code.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Question about execl, replacing process's contents

I'm reading Operating Systems in Depth by Thomas W. Doeppner, and I have a question about execl. He says it's called after fork(), and that it replaces the text (code) of the current process and replaces it with the code of the new program. But that doesn't make sense to me. Does that mean... (4 Replies)
Discussion started by: SirSalt
4 Replies

2. UNIX for Dummies Questions & Answers

Problem with iptables while doing tftp.

Hi all, I have a problem. I have iptables enabled in my ubuntu system on which tftp server is configured. Now when I try to do a tftpget from another ubuntu 32-bit machine, file transfer is not happening. But, when iptables are disabled, everything is fine. I heard that some ip_conntrack module... (0 Replies)
Discussion started by: sai2krishna
0 Replies

3. UNIX for Dummies Questions & Answers

[Quick question]Problem with execl and GREP

Guys, I have the following code #include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/wait.h> #include <unistd.h> void read2(); main(int argc, char** argv) { int pid,status; pid=fork(); if ( pid == 0 ) { read2(argv,... (4 Replies)
Discussion started by: pfpietro
4 Replies

4. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

5. UNIX for Advanced & Expert Users

how to start a process killable by all

Hi, Is there a way to start a process that any other user would have the privs to kill? Thanks. (1 Reply)
Discussion started by: rebelbuttmunch
1 Replies

6. UNIX for Dummies Questions & Answers

cant start httpd process

httpd status is stopped.cant start it again by : /etc/init.d/httpd restart or /etc/init.d/httpd/start help needed (2 Replies)
Discussion started by: raksha.s
2 Replies

7. Shell Programming and Scripting

Script - How to automatically start another process when the previous process ends?

Hi all, I'm doing automation task for my team and I just started to learn unix scripting so please shed some light on how to do this: 1) I have 2 sets of datafiles - datafile A and B. These datafiles must be loaded subsequently and cannot be loaded concurrently. 2) So I loaded datafile A... (10 Replies)
Discussion started by: luna_soleil
10 Replies

8. Linux

tftp will not start.

I have setup nimol on a Fedora 9 machine. Nimol is installed and correctly configured and I have a client rs6000 (43p) declared in the dhcpd.conf file. all is running correctly and tftp is installed. I am monitoring /var/log/messages when I start the 43p and see the dhcp request come in and a reply... (0 Replies)
Discussion started by: johnf
0 Replies

9. Solaris

tftp Problem during Jumpstart

Hi, I have a V240 Solaris 10 (06.06) with a Solaris image of 08.07 (newest release). On the jumpstart server I have also installed JET for testing. Client was setup using the JET utilities. jade = jumpstart server phoebus = client (MAC: 0:3:ba:9e:6f:2d IP:192.168.58.121 ) When I now... (0 Replies)
Discussion started by: Ironhead
0 Replies

10. Shell Programming and Scripting

how to start a process and make it sleep for 5 mins and then kill that process

how to start a process and make it sleep for 5 mins and then kill that process (6 Replies)
Discussion started by: shrao
6 Replies
Login or Register to Ask a Question