Sponsored Content
Homework and Emergencies Homework & Coursework Questions Help with Execl system call in a C program? Post 302898509 by miniviking10 on Tuesday 22nd of April 2014 01:26:29 PM
Old 04-22-2014
I am not saying it is his fault that I do not understand it. I am the one asking for help, but he went on the give me an example of using execl using a built-in command(date) when I specifically said in the OP that I already have been given an example of using execl with a command ("The only example done in class by the professor was calling the ps command which is a command and not a script.") when I'm trying to figure out how to use it with calling a script I have made myself. He then proceeded to tell me to pay attention to what I'm doing which irked me because I feel like I'm paying quite a bit of attention to what I'm doing.

With that said, thanks for pointing out my typo.

Where you say it needs the name of the file, are you saying I should do this?...

execl("/home/dl121/cs371/assn7/a7.sh", "a7.sh", NULL);

Because, I do have the name of the file in the second argument already.

---------- Post updated at 12:26 PM ---------- Previous update was at 12:19 PM ----------

OKAY, got it.

Changed it to:

Code:
execl("/home/dl121/cs371/assn7/a7.sh", "a7.sh", NULL);

And it ran my a7.sh script. Although, it printed my output twice in both the parent and child class. Not sure if that's how it's supposed to be, but at least it's running the script which is the main thing I wanted. Thanks.
This User Gave Thanks to miniviking10 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

how to differentiate system call from library call

Hi, Ho do I differentiate system call from library call? for example if I am using chmod , how do I find out if it is a system call or library call? Thanks Muru (2 Replies)
Discussion started by: muru
2 Replies

2. Programming

parent not waiting until child complete executing another program through execl()

Hi, I am calling a program that greps and returns 72536 bytes of data on STDOUT, say about 7000 lines of data on STDOUT. I use pipe from the program am calling the above program. Naturally, I execute the above program (through execl() ) throught the child process and try to read the... (4 Replies)
Discussion started by: vvaidyan
4 Replies

3. Shell Programming and Scripting

how to call another program

Hi, I would like to know how to call a program "cmp_size" ... where to put in progam to run it ex: program checkdisk is below, and it will call a nother problem "cmp_size" Do I just put the cmp_size program at the end of this program. Thank you very much, # check all directory for size... (3 Replies)
Discussion started by: xitrum
3 Replies

4. Programming

A question about the system call mount in a C program

Dear all, Currently I'm working on a C program (OS = ubuntu 9.0.4)in which a USB key will be mounted and umounted for several times. I read the man page of the mount system call. I use the following test code #include <sys/mount.h> int main(int argc, char *argv) { if... (5 Replies)
Discussion started by: dariyoosh
5 Replies

5. Shell Programming and Scripting

Run shell script from C program by calling fork and execl

I need to write a c program that uses the fork and excel system calls to run the shell script mode invoked like this: "./mode 644 ls -l" (that is the argumetns will always be 644 ls -l) here's the mode script: #!/bin/sh octal="$1" shift find . -maxdepth 1 -perm $octal -exec $@ {} \; ... (3 Replies)
Discussion started by: computethis
3 Replies

6. Shell Programming and Scripting

Call a mainframe program

Is it possible to call a mainframe program in UNIX script. I am using HP-UNIX. If so can any let me know the way to do it. (1 Reply)
Discussion started by: atlantis
1 Replies

7. Programming

Notification email in C program, via system call? or?

Hello everyone! I'm quite new here, but this forum helped me a lot before without registering :-) I'll go directly to my problem, I have been searching a bit about this issue but I was not successful. I need to write a program in C code to notificate me (to my email) when some action is done... (7 Replies)
Discussion started by: RoNNo
7 Replies

8. Homework & Coursework Questions

program to send messages to parent using pipes and select system call

Write a program using select, which will create some number of child processes that continuously send text messages to the parent process using pipes. Each child has its own pipe that it uses to communicate with the parent. The parent uses select () to decide what pipes should be processed to... (1 Reply)
Discussion started by: ripssingh
1 Replies

9. Shell Programming and Scripting

printf before execl system call

main() { printf("before execl"); execl("/home/nirmala/os/fact","fact"); printf("this line will not be printed"); } for the above program ,the obj file of fact.c is getting loaded correctly.am getting the output as... factorial =6 but in ouput am not getting the string given in... (2 Replies)
Discussion started by: pnirmala
2 Replies

10. Programming

call program

I would need to call the program 'ethtool' in my C++ program, does anyone know how to do that (if its even possible)? (1 Reply)
Discussion started by: Freaky123
1 Replies
EXEC(2) 							System Calls Manual							   EXEC(2)

NAME
exec, execl, _clock - execute a file SYNOPSIS
#include <u.h> #include <libc.h> int exec(char *name, char* argv[]) int execl(char *name, ...) long *_clock; DESCRIPTION
Exec and execl overlay the calling process with the named file, then transfer to the entry point of the image of the file. Name points to the name of the file to be executed; it must not be a directory, and the permissions must allow the current user to execute it (see stat(2)). It should also be a valid binary image, as defined in the a.out(6) for the current machine architecture, or a shell script (see rc(1)). The first line of a shell script must begin with followed by the name of the program to interpret the file and any initial arguments to that program, for example #!/bin/rc ls | mc When a C program is executed, it is called as follows: void main(int argc, char *argv[]) Argv is a copy of the array of argument pointers passed to exec; that array must end in a null pointer, and argc is the number of elements before the null pointer. By convention, the first argument should be the name of the program to be executed. Execl is like exec except that argv will be an array of the parameters that follow name in the call. The last argument to execl must be a null pointer. For a file beginning #!, the arguments passed to the program (/bin/rc in the example above) will be the name of the file being executed, any arguments on the #! line, the name of the file again, and finally the second and subsequent arguments given to the original exec call. The result honors the two conventions of a program accepting as argument a file to be interpreted and argv[0] naming the file being exe- cuted. Most attributes of the calling process are carried into the result; in particular, files remain open across exec (except those opened with OCEXEC OR'd into the open mode; see open(2)); and the working directory and environment (see env(3)) remain the same. However, a newly exec'ed process has no notification handler (see notify(2)). When the new program begins, the global cell _clock is set to the address of a cell that keeps approximate time expended by the process at user level. The time is measured in milliseconds but is updated at a system-dependent lower rate. This clock is typically used by the profiler but is available to all programs. The above conventions apply to C programs; the raw system interface to the new image is as follows: the word pointed to by the stack pointer is argc; the words beyond that are the zeroth and subsequent elements of argv, followed by a terminating null pointer; and the return register (e.g. R0 on the 68020) contains the address of the clock. Alef In Alef, the intent and syntax are the same but the implementation is different. Exec (or execl; this description applies to either) may be called only by a proc holding a single task, typically the implicit main task of the proc. First, access(2) is called to see if the named file exists and has execute permission. If not, exec returns -1 immediately. Otherwise, it will never return: it frees resources private to the invoking proc and calls the exec system call. If this fails, it calls the bare _exits system call (see exits(2)) with the error string as argument. Therefore, if the file looks executable, the calling process is lost, whether the exec succeeds or not. SOURCE
/sys/src/libc/9syscall /sys/src/libc/port/execl.c SEE ALSO
intro(2), stat(2) DIAGNOSTICS
If these functions fail, they return and set errstr. There can be no return from a successful exec or execl; the calling image is lost. EXEC(2)
All times are GMT -4. The time now is 12:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy