Signal out from fork()'d shell script back to the C++ application


 
Thread Tools Search this Thread
Top Forums Programming Signal out from fork()'d shell script back to the C++ application
# 1  
Old 02-12-2014
Signal out from fork()'d shell script back to the C++ application

Hi,
I am writing a C++ application; in which at one point I fork() a new process, which executes a shell script (via execv() call).
Now the shell script can take a while to finish (tarring, burning a cd, etc.) and I would like to update the parent application about the progress (while the script is running).
Any ideas on how to do this?
Thank you!
Miro
# 2  
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:
# 3  
Old 02-12-2014
On a whole lot less imaginative vector:

6 Linux Interprocess Communications

There are umpteen different IPC mechanisms. -- basically: semaphores, mutexes, msg queues, locks, signals, shared memory, plain files, pipes. And lots of variants.
This User Gave Thanks to jim mcnamara For This Post:
# 4  
Old 02-12-2014
Fantastic!
Thank you guys for pointing me in the right direction!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

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

10. 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
Login or Register to Ask a Question