11-20-2009
Thanks a lot, you gave me new ideas
10 More Discussions You Might Find Interesting
1. Programming
When executing this simple program:
#include <unistd.h>
void main()
{
int f;
printf("\n Parent procces ID=%d\n",getpid());
f=fork();
if(f==0)
{
printf("\n Child process ID=%d father=%d\n",getpid(),getppid());
}
... (2 Replies)
Discussion started by: bb666
2 Replies
2. Shell Programming and Scripting
I have my inputfile in the following format :
From:sdhfhg
dsfhsdjfjdsfh
dsfjdjshjsd
djfhsdjfjsdhjds
Error Description
<aa.aa.aa.aa.aa.aa>
From:ksljfsdhfjh
djfdsjkf
sdjwoquk
dsfsdfj
Error Description
<dd.dd.dd.dd.dd>
I want to read the lines from tag 'From:' thrul <aa.aa.aa.aa.aa.aa>... (1 Reply)
Discussion started by: Amruta Pitkar
1 Replies
3. Programming
Hello experts,
I am using fork() in my code but I am confused which output comes first child or parent?
I did the following code .My book shows parent first but my linux shows child first.Can anyone tell me why?
#include <stdio.h>
int main(){
int pid;
printf("I am original process with pid... (5 Replies)
Discussion started by: mlhazan
5 Replies
4. Programming
Assume we have an application built on *nix that uses fork()...then the processes procedure is going to act as follow:
X is considered a parent process (first click on application)
Y is considered a child process of X (second click on application)
Z is considered a child process of Y (third... (6 Replies)
Discussion started by: f.ben.isaac
6 Replies
5. Shell Programming and Scripting
hi,
i start using awk and have a very basic problem. here's my code:
#! /usr/bin/awk -f
# 2010, scz
#
{
$1 == "test" { print $2 }
}
this works on the command line but not as "program" - what is the difference between awk programs on the command line and executing awk... (3 Replies)
Discussion started by: svencz
3 Replies
6. Programming
I writing a program that forks three times but only on the parent process. The three children processes then produces output in order. 1, 2, 3. I am confused on how to do this. I have tried multiple if and else if statements but the output does not come out right. How should I go about doing this? (1 Reply)
Discussion started by: TWhitt24
1 Replies
7. Programming
Hello everybody.I want to make clear that i am not going to ask from anybody to build my asignement but i have a big problem. I can't seem to find anywhere ONE good example on C about what i am trying to do:wall:.I think it is simple. All i ask is one example, even a link is fine.
So, i want to... (1 Reply)
Discussion started by: Cuervo
1 Replies
8. Programming
i'm experimenting fork function and i found this code
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <wait.h>
#include <fcntl.h>
#include <unistd.h>
int main(void)
{
int fd;
pid_t p;
p = fork();
fork();
if (p>0) { fork();}
fork();
fork();... (6 Replies)
Discussion started by: blob84
6 Replies
9. Programming
Hi All,
I have a program for class that needs to do the following:
1. Print the directory entries from the current directory using ncurses
2. Provide a prompt next to each directory entry and allow the user to enter commands that may or may not be about the file
3. Execute those commands in... (1 Reply)
Discussion started by: afulldevnull
1 Replies
10. UNIX for Beginners Questions & Answers
Hello... And thanks in advance for any help anyone can offer me on my question! I've been doing a lot of reading to try and find my answer... But I haven't had any luck
What I'm trying to understand is where a child process inherits global environment variables from? I understand the exec()... (2 Replies)
Discussion started by: bodisha
2 Replies
LEARN ABOUT MOJAVE
daemon
DAEMON(3) BSD Library Functions Manual DAEMON(3)
NAME
daemon -- run in the background
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <stdlib.h>
int
daemon(int nochdir, int noclose);
DESCRIPTION
The daemon() function is for programs wishing to detach themselves from the controlling terminal and run in the background as system daemons.
The fork(2) system call is used; see CAVEATS below about the environment after a fork() (without a corresponding call to one of the exec rou-
tines). On Mac OS X, the use of this API is discouraged in favor of using launchd(8).
Unless the argument nochdir is non-zero, daemon() changes the current working directory to the root (/).
Unless the argument noclose is non-zero, daemon() will redirect standard input, standard output, and standard error to /dev/null.
RETURN VALUES
The daemon() function returns the value 0 if successful; otherwise the value -1 is returned and the global variable errno is set to indicate
the error.
ERRORS
The daemon() function may fail and set errno for any of the errors specified for the library functions fork(2) and setsid(2).
SEE ALSO
fork(2), launchd(8), setsid(2), sigaction(2)
HISTORY
The daemon() function first appeared in 4.4BSD.
CAVEATS
There are limits to what you can do in the child process. To be totally safe you should restrict yourself to only executing async-signal
safe operations (see sigaction(2)) until such time as one of the exec functions is called. All APIs, including global data symbols, in any
framework or library should be assumed to be unsafe after a fork() unless explicitly documented to be safe or async-signal safe. If you need
to use these frameworks in the child process, you must exec. In this situation it is reasonable to exec yourself.
Unless the noclose argument is non-zero, daemon() will close the first three file descriptors and redirect them to /dev/null. Normally,
these correspond to standard input, standard output, and standard error. However, if any of those file descriptors refer to something else,
they will still be closed, resulting in incorrect behavior of the calling program. This can happen if any of standard input, standard out-
put, or standard error have been closed before the program was run. Programs using daemon() should therefore either call daemon() before
opening any files or sockets, or verify that any file descriptors obtained have values greater than 2.
The daemon() function temporarily ignores SIGHUP while calling setsid(2) to prevent a parent session group leader's calls to fork(2) and then
_exit(2) from prematurely terminating the child process.
BSD
June 9, 1993 BSD