Sponsored Content
Top Forums Programming C function to start process but to return right away Post 302428043 by JCR on Tuesday 8th of June 2010 03:45:06 PM
Old 06-08-2010
Thanks! I like the strategy. I am putting those codes inside a fastcgi program:

Code:
int main(void)
{
  initialize();
  while (FCGI_Accept() >= 0)  
  {
		  pid_t pid = fork();
		  if(pid < 0)
		  {
		    exit(1);
		  }
		  else if(pid == 0)
		  {
		    //do things
				  continue;
		  }
		  bstring s = bfromcstr("Content-type: text/html\n\n");

    bcatcstr(s, "hellow");
    printf("%s",s->data);
  }
  return EXIT_SUCCESS;
}

From initial testing, it works fine. Do you see any pitfalls though?

Thanks agains
 

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

return value of a function

Hi I have a doubt in the way the variables inside a function are treated . if a function is called from the main script directly, the variables inside them act as global variables. however if the return value of the function is stored to some other variable in the main script as shown,... (3 Replies)
Discussion started by: prez
3 Replies

3. 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

4. Shell Programming and Scripting

return value of a function

I have write a shell function to get the maximum of a vector. However, the returned value from the function is not always the correct one. Here is the script: maxval() { local max j i size arrval size=$1 ; shift max=-999999999 i=0 while do arrval="$1" if then ... (5 Replies)
Discussion started by: fl0r10
5 Replies

5. Shell Programming and Scripting

return in function

I am using ksh. I want to know how can we make any function to return string or double value. I dont want to use the global variables. (5 Replies)
Discussion started by: PRKS
5 Replies

6. Shell Programming and Scripting

Return a value from called function to the calling function

I have two scripts. script1.sh looks -------------------------------- #!/bin/bash display() { echo "Welcome to Unix" } display ----------------------------- Script2.sh #!/bin/bash sh script1.sh //simply calling script1.sh ------------------------------ (1 Reply)
Discussion started by: mvictorvijayan
1 Replies

7. 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

8. Shell Programming and Scripting

Pass return value of a function in background process

Hi, I have created a function f1 defined in script A.sh .I have called this function in background . But I want to use its return value for another function f2 in script A.sh. I tried declaring it as a global variable, yet it always returns the status as 0. Is there any way with which I can get... (7 Replies)
Discussion started by: ashima jain
7 Replies

9. Shell Programming and Scripting

Return: can only `return' from a function or sourced script

Not sure where the problem is. I can run the script without any issue using the following command. . /opt/app/scripts/cdc_migration.sh But it fails with the below error when I try it this way /opt/app/scripts/cdc_migration.sh /opt/app/scripts/cdc_migration.sh: line 65: return: can only... (1 Reply)
Discussion started by: svajhala
1 Replies

10. Shell Programming and Scripting

Function - Make your function return an exit status

Hi All, Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition. #Body function1() { if then echo "exist" else echo "not exist" } #if not exist in function1 my all other function will not proceed.... (4 Replies)
Discussion started by: meister29
4 Replies
waitid(2)							System Calls Manual							 waitid(2)

NAME
waitid - wait for child process to change state SYNOPSIS
DESCRIPTION
The function suspends the calling process until one of its children changes state. It records the current state of a child in the structure pointed to by infop. If a child process changed state prior to the call to returns immediately. The idtype and id arguments are used to specify which children will wait for. If idtype is will wait for the child with a process ID equal to (pid_t)pid. If idtypeis will wait for any child with a process group ID equal to (pid_t)pid. If idtypeis will wait for any children and id is ignored. The options argument is used to specify which state changes will wait for. It is formed by OR-ing together one or more of the following flags: Wait for processes that have exited. Status will be returned for any child that has stopped upon receipt of a signal. Status will be returned for any child that was stopped and has been continued. Return immediately if there are no children to wait for. Keep the process whose status is returned in infop in a waitable state. This will not affect the state of the process; the process may be waited for again after this call completes. The infop argument must point to a structure. If returns because a child process was found that satisfied the conditions indicated by the arguments idtype and options, then the structure pointed to by infop will be filled in by the system with the status of the process. The si_signo member will always be equal to RETURN VALUE
If returns due to the change of state of one of its children, 0 is returned. Otherwise, -1 is returned and is set to indicate the error. ERRORS
The function will fail if: [ECHILD] The calling process has no existing unwaited-for child processes. [EINTR] The function was interrupted due to the receipt of a signal by the calling process. [EINVAL] An invalid value was specified for options, or idtype and id specify an invalid set of processes. APPLICATION USAGE
Threads Considerations In a multi-threaded application, only the calling thread is suspended by will not return until all threads in the process have reached the desired state. For example, if the or options are specified, will not return until all threads in the process have terminated, stopped or continued respectively. SEE ALSO
exec(2), exit(2), wait(2), <sys/wait.h>. CHANGE HISTORY
First released in Issue 4, Version 2. waitid(2)
All times are GMT -4. The time now is 04:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy