Sponsored Content
Full Discussion: wait system call
Top Forums Programming wait system call Post 47464 by a25khan on Wednesday 11th of February 2004 07:26:02 AM
Old 02-11-2004
wait system call

hi there,
i had some trivial questions about this program here. i am kinda confused with these, hope you can help me to understand here. Smilie

#include<stdio.h>
#include<sys/wait.h>
#include<sys/types.h>
#include<unistd.h>

int main(void)
{
int i,status,waitret;

for(i=0;i<3;i++)
{
if(fork()==0)
{
if(execl("exec2","exec2",0)== -1)
{
fprintf(stderr,"Child: execl failed\n");
exit(1);
}
}

printf("Parent: continuing execution after fork %d\n",i);
}
/** we see above the parent execution lasted till the closing
brace "}". now below we call the status function. what is the
calling process here? i mean which process gave a call to the function status? is it parent? if it's parent then my question is well we called
for fork inside the for loop and i guess it is supposed to run child and
parent process in the loop only. my confusion builds up in the statement
i am about to write. i read in the text "The wait function suspends the
calling process until one of its immediate child processes terminates. The
termination status of the child process is stored in the integer pointed
to by status. If the calling process does not care about the termination
status, and is only interested in waiting until the child process
terminates, status may be given as the null pointer. If a child process
has terminated prior to the call to wait , wait returns immediately with
the status for that process. The process ID of the process that terminated
is returned by wait; if there are no unwaited-for child processes, wait
returns -1." */

for(i=0;i<3;i++)
{
waitret=wait(&status);
/** wait function is going to return an int value, what is
the purpose of using the function here? what is the calling process here?
what is the termination status of child here? in fork we get the pid of
the child, but what exactly is the termination status? is it gona return
1 on success and 0 on failure if for termination? as seeen above the
child terminates prior to the call of wait, so is wait going to return
the status immediately? what if the wait was called from within the
child process? would that still return immediately? if you read above
it said " The process ID of the process that terminated
is returned by wait". whats the use of it, if we can get the pid of the process by using getpid() or getppid()? */
printf("Status from wait: %d (decimal), %x
(hex)\n",status,status);
}
/** another question: i thought the parent ended after the for loop was
over, we called for fork within that loop, so isn't the parent restricted
to live inside the opening and closing braces only!? */
printf("Parent: Ending\n");
}

Appreciate your answer.
Cheers!
 

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

c system call

How the c compiler differentiates the system calls and function calls? (1 Reply)
Discussion started by: rangaswamy
1 Replies

3. Shell Programming and Scripting

wait command - cat it wait for not-chile process?

Did not use 'wait' yet. How I understand by now the wait works only for child processes, started background. Is there any other way to watch completion of any, not related process (at least, a process, owned by the same user?) I need to start a background process, witch will be waiting... (2 Replies)
Discussion started by: alex_5161
2 Replies

4. Shell Programming and Scripting

system call

Hi, How to write a system calls in a script ? > cd $HOME > ls -ltr thanks in advance.. (10 Replies)
Discussion started by: hegdeshashi
10 Replies

5. Programming

C:system call

Hi I'm studing the system call. I've written a small program that return the time spent in doing some operations. Now I'd like to write one that return the time spent in user mode of a process. I'm reading that i should use the tms struct: clock_t times(struct tms *buf); struct tms {... (2 Replies)
Discussion started by: Dedalus
2 Replies

6. Programming

system call

I have a cgi script which is called after certain time interval, which has this: system ("ls -l /tmp/cgic* | grep -v \"cgicsave.env\" | awk '{print $5}'"); During the execution of this script,the output is 0 sometimes. But due to this the system call is not working at all and doesnt o/p... (2 Replies)
Discussion started by: xs2punit
2 Replies

7. Programming

need help with system call

hi everyone i wrote a system call and compiled the kernel succesfully... my system call is in a file in the kernel folder named my_syscall1.c (kernel/my_syscall1.c) the header file for this system call i added it in the folder include like this include/my_syscall1/my_syscall1.h my problem is... (2 Replies)
Discussion started by: demis87
2 Replies

8. Shell Programming and Scripting

system call

Trying to figure out a load issue with a webserver. I have traced a php script and noticed the following connect(4, {sa_family=AF_INET, sin_port=htons(3306), sin_addr=inet_addr("XX.XX.XX.XX")}, 16) = -1 EINPROGRESS (Operation now in progress) <0.000035> poll(, 1, 2000) = 1 () <0.000120>... (5 Replies)
Discussion started by: rajan007
5 Replies

9. Programming

C: error in wait system call

i made this program but when i compile this code, compiler make this error, is an error on wait() system call but argumenti is right, or not?: esercizio.c:80:9: error: incompatible type for argument 1 of ‘wait' /usr/include/i386-linux-gnu/sys/wait.h:116:16: note: expected ‘__WAIT_STATUS' but... (4 Replies)
Discussion started by: tafazzi87
4 Replies

10. UNIX for Dummies Questions & Answers

Call a UNIX script inside another and dont wait for it

Hi I have two scripts script1.sh and script2.sh(say this script is a long running). I want to call script2.sh inside and script1.sh,but when i call script2.sh i dont want to wait for script2 to complete and want this to run in back ground and go on next commands in script 1.sh and finally at the... (2 Replies)
Discussion started by: lijjumathew
2 Replies
rmmod(8)						      System Manager's Manual							  rmmod(8)

NAME
rmmod -- simple program to remove a module from the Linux Kernel SYNOPSIS
rmmod [-f] [-w] [-s] [-v] [modulename] DESCRIPTION
rmmod is a trivial program to remove a module (when module unloading support is provided) from the kernel. Most users will want to use modprobe(8) with the -r option instead. OPTIONS
-v --verbose Print messages about what the program is doing. Usually rmmod prints messages only if something goes wrong. -f --force This option can be extremely dangerous: it has no effect unless CONFIG_MODULE_FORCE_UNLOAD was set when the kernel was compiled. With this option, you can remove modules which are being used, or which are not designed to be removed, or have been marked as unsafe (see lsmod(8)). -w --wait Normally, rmmod will refuse to unload modules which are in use. With this option, rmmod will isolate the module, and wait until the module is no longer used. Nothing new will be able to use the module, but it's up to you to make sure the current users eventually finish with it. See lsmod(8)) for information on usage counts. -s --syslog Send errors to syslog instead of standard error. -V --version Show version of program and exit. COPYRIGHT
This manual page originally Copyright 2002, Rusty Russell, IBM Corporation. Maintained by Jon Masters and others. SEE ALSO
modprobe(8), insmod(8), lsmod(8) modinfo(8) rmmod(8)
All times are GMT -4. The time now is 03:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy