could some assist please


 
Thread Tools Search this Thread
Top Forums Programming could some assist please
# 1  
Old 02-17-2003
could some assist please

i was searching on the net have found a couple of sample programs and was wondering if some could tell me what they do cheers.

main()
{
printf("Executing ls\n");
execl("/bin/ls","ls","-l", (char *)0);
perror("execl failed to run ls");
exit(1);
}



main()
{
int i;

i = fork();
if (i == 0)
{
printf("Child. getpid() = %d, getppid() = %d\n", getpid(), getppid());
sleep(5);
printf("After sleeping. getpid() = %d, getppid() = %d\n",
getpid(), getppid());
}
else
{
printf("Parent exiting now\n");
}
}


thanks in advance guys
# 2  
Old 02-17-2003
the first one executes the command /bin/ls .
i have an idea what the second one does but im not really sure. they both are safe to run so if you have a working compiler you should run them to find out.
# 3  
Old 02-17-2003
ruff, are you sure these are not homework problems? The both seem like the kind of problems that a teacher would ask students to analyze ..... especially the forking template.

Could you provide the URL(s) of where you found these on the net? Thanks.
# 4  
Old 02-18-2003
no actaully it is real i was searching on the internet to help me learn more about c due to me being only new to coding, and found these code examples and they looked more advanced and interesting so was wondering what they meant mate.

http://angelfire.lycos.com/clone2/coding/index.html
# 5  
Old 02-18-2003
For the first one, execl() is a function that will cause the program to overlayed by a different program. It's still same process, but it's now a different program. If execl() works, then we will never return from it. So if we do return, something went wrong. That's why it has that perror() and an exit(1).

The second one uses fork() which creates a second process. Both processes will return from the fork(). The child process will see a return code of 0. And the parent will see a return code of a positive integer which is the pid of the newly created child. So by testing that return code, the programmer can make the parent and the child do something different.
# 6  
Old 02-21-2003
thanks guys appreciate it
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Red Hat

assist me in UNIX scripting

hi ... i want to monitor the httpd service whether its online or offline.. if httpd service goes offline/stopped then i need to get alert to my mail. how to do construct this script.. myself using RHEL4 ... (1 Reply)
Discussion started by: sriniv666
1 Replies

2. Shell Programming and Scripting

In need of assist....

How would i take the output of a file dump it into another file while at the same time sorting it? this is my script..simple i know!? echo "Enter the file log you wish to use. : " read file awk '{print $1,$2,$4,$5}' $file >> list Im trying to dump it into that list file and sort it at... (6 Replies)
Discussion started by: jspinal
6 Replies

3. Shell Programming and Scripting

Need of a Parsing Script Assist...

Im trying to find a script that will pull ip addresses along with the date and time sort it by ip addresses and output it to a file... As a newbie to scripting im kinda stumped here...and suggestions? (2 Replies)
Discussion started by: jspinal
2 Replies

4. UNIX for Dummies Questions & Answers

Please Assist

I try taip this script below...but i have got error.The error message is Input read error..Anybody can see whether my script have problem.Below this is my script: #!/bin/sh filename=test.txt vi $filename <<EndOfCommands i This file was created automatically from a shell script ^ (1 Reply)
Discussion started by: mastercar
1 Replies

5. Shell Programming and Scripting

New to KSH Scripting > Please Assist!

Array Example: $ colors=RED $ colors=GREEN $ colors=BLUE (4 Replies)
Discussion started by: ora_umair
4 Replies

6. HP-UX

Assist me in doing certification please

Hi Everybody, Iam new to the unix world but interested a lot to know about unix. i want to do a certification course in unix so can anybody please suggest me what course can i do for unix adminstration and what books do i have to refer to. Thanks in Advance. (5 Replies)
Discussion started by: ajazshariff
5 Replies

7. UNIX for Dummies Questions & Answers

Script Assist

Hello all I am new and I had a question that I was hoping you could answer. I am using mutt on a directory in this directory will be pdf files named 001.pdf , 002.pdf and so on. I need a script that can read the filename and associate that with a user like so : if 001.pdf exists then email... (16 Replies)
Discussion started by: linuxguy30350
16 Replies
Login or Register to Ask a Question