Sponsored Content
Top Forums Programming Signal out from fork()'d shell script back to the C++ application Post 302888138 by Don Cragun on Wednesday 12th of February 2014 07:54:19 PM
Old 02-12-2014
The parent application can set up standard output of the shell script to be the write end of a pipe that the parent can use to read status from the child.

The parent can create a named pipe (or regular file) and pass the name of that file to the shell script as an operand. The child can then write status to that file and the parent can read status from that file.

The parent can set up a signal catching function for a signal and pass its process ID to the child shell script. The child can then use:
Code:
kill -signal_name parent_process_ID

to notify the parent that some milestone has been reached.

Use your imagination... There are lots of ways for one process to talk to another process.
This User Gave Thanks to Don Cragun For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

shell script signal handler

AIX 4.3.3 I am trying to write a signal handler into a ksh shell script. I would like to capture the SIGTERM, SIGINT, and the SIGTSTP signals, print out a message to the terminal, and continue executing the script. I have found a way to block the signals: #! /bin/ksh SIGTERM=15 SIGINT=2... (2 Replies)
Discussion started by: jalburger
2 Replies

2. UNIX for Advanced & Expert Users

signal handling in shell script

Hi can any please tell me is it possible to catch the signal in a shell script like we do in C. if yes please give me some idea or a link. (4 Replies)
Discussion started by: Raom
4 Replies

3. Shell Programming and Scripting

how to write shell script to take back up

Helo, I want to write shell script which takes back of all binaries (exe files). and when i uninstall the upgraded system which automatically restore the old binary which we have take as back up. can u tell me how to write such shell scripts. Regards, Amit (5 Replies)
Discussion started by: amitpansuria
5 Replies

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

5. Shell Programming and Scripting

How to ADD signal stop commands in Shell Script

Hi , I do have a shell which test the connectivity using ssh, soon after the login it should use the keys Ctrl + z or Ctrl + c to exit from login promt. So how do i need to implement these . (3 Replies)
Discussion started by: raghunsi
3 Replies

6. Shell Programming and Scripting

How trap a signal in shell script?

Hi , i have a scenario where...i have to put a check where if script is executing more than 15mins i have to kill that script and n retry again 2nd time. i this case i can use background process to do it but i feel trap will be the efficent way to do so... but i dont know much about it... (1 Reply)
Discussion started by: crackthehit007
1 Replies

7. Shell Programming and Scripting

how to suppress the status of fork in shell script

When command is executed by forking, the console displays the status of that command. I want to suppress it.. how to do it ? Example: var1=`date` & echo "hello world"; output: hello world + Done var1=`date` I want to suppress the second line "+ Done var1=`date`". I... (10 Replies)
Discussion started by: Arun_Linux
10 Replies

8. Shell Programming and Scripting

Help: how to call fork() in shell script? New to linux

Hi, I'm writing a shell script where I want to call fork(). However I wrote like this "var=fork()" in c style and got this error: "syntax error near unexpected token `(' " How could I call fork() in shell script? Thanks in advance. Duplicate Post - Continue Here - Please Do Not Cross Post... (0 Replies)
Discussion started by: Xiaoya
0 Replies

9. Ubuntu

Help: how to call fork() in shell script? New to linux

Hi, I'm writing a shell script where I want to call fork(). However I wrote like this "var=fork()" in c style and got this error: "syntax error near unexpected token `(' " How could I call fork() in shell script? Thanks in advance. (2 Replies)
Discussion started by: Xiaoya
2 Replies

10. Shell Programming and Scripting

Passing control back to the shell script

Hi All, I have a shell script(test_abc.sh) with the following shell commands, which are invoking the same shell script with different parameters. test_abc.sh . ./test.sh abc >> test.log . ./test.sh xyz >> test.log . ./test.sh pys >> test.log . ./test.sh abc >> test.log . . ... (4 Replies)
Discussion started by: dev.devil.1983
4 Replies
pthread_atfork(3)					     Library Functions Manual						 pthread_atfork(3)

NAME
pthread_atfork - Declares fork handler routines to be called when the calling thread's process forks a child process. LIBRARY
Standard C Library (libc.so, libc.a) SYNOPSIS
#include <pthread.h> int pthread_atfork( void (*prepare)(void), void (*parent)(void), void (*child)(void)); STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: IEEE Std 1003.1c-1995, POSIX System Application Program Interface PARAMETERS
Address of a routine that performs the fork preparation handling. This routine is called in the parent process before creating the child process. Address of a routine that performs the fork parent handling. This routine is called in the parent process after creating the child process and before returning to the caller of fork(2). Address of a routine that performs the fork child handling. This routine is called in the child process before returning to the caller of fork(2). DESCRIPTION
This routine allows a main program or library to control resources during a fork(2) operation by declaring fork handler routines, as fol- lows: The fork handler routine specified in the prepare argument is called before fork(2) executes. The fork handler routine specified in the parent argument is called after fork(2) executes within the parent process. The fork handler routine specified in the child argument is called in the new child process after fork(2) executes. Your program (or library) can use fork handlers to ensure that program context in the child process is consistent and meaningful. After fork(2) executes, only the calling thread exists in the child process, and the state of all memory in the parent process is replicated in the child process, including the states of any mutexes, condition variables, and so on. For example, in the new child process there might exist locked mutexes that are copies of mutexes that were locked in the parent process by threads that do not exist in the child process. Therefore, any associated program state might be inconsistent in the child process. The program can avoid this problem by calling pthread_atfork to provide routines that acquire and release resources that are critical to the child process. For example, the prepare handler should lock all mutexes that you want to be usable in the child process. The parent handler just unlocks those mutexes. The child handler will also unlock them all--and might also create threads or reset any program state for the child process. If no fork handling is desired, you can set any of this routine's arguments to NULL. NOTES
It is not legal to call pthread_atfork from within a fork handler routine. Doing so could cause a deadlock. EXAMPLES
For example, if your library uses a mutex my_mutex, you might provide pthread_atfork handler routines coded as follows: void my_prepare(void) { pthread_mutex_lock(&my_mutex); } void my_parent(void) { pthread_mutex_unlock(&my_mutex); } void my_child(void) { pthread_mutex_unlock(&my_mutex); /* Reinitialize state that doesn't apply...like heap owned */ /* by other threads */ } { . . . pthread_atfork(my_prepare, my_parent, my_child); . . fork(); } RETURN VALUES
If an error condition occurs, this routine returns an integer value indicating the type of error. Possible return values are as follows: Successful completion Insufficient table space exists to record the fork handler routines' addresses. ERRORS
None RELATED INFORMATION
Functions: pthread_create(3) Manuals: Guide to DECthreads, Programmer's Guide delim off pthread_atfork(3)
All times are GMT -4. The time now is 07:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy