how to delay a process from getting killed


 
Thread Tools Search this Thread
Top Forums Programming how to delay a process from getting killed
# 1  
Old 01-20-2009
Error how to delay a process from getting killed

We are forking a process B from process A and the process B should display the details it reads from process C(daemon process) continuously.
Let us say that the process C sents 100 packets.The process B receives all the 100 packets from the process C before it prints all details of 31 packets.Since the process B recieved all the 100 packets it gets killed.
If we press ctrl-c(sends SIGINT signal) after the receival of 31 packets i.e, after the process B got killed.the process A also gets killed & it is not displaying the remaining packets since the buffer gets cleared.Can anyone help me to know how to delay the process A or process B from being killed before it displays all the 100 packets.

Thanks in Advance,
Megala.C

Last edited by cijkmysj; 01-21-2009 at 12:25 AM..
# 2  
Old 01-29-2009
First, I don't think you want to "Delay" the process from being killed. You merely want to call fflush() after every output. (Are you using buffered I/O, ie, printf? Or are you using write() to print? Probably the former, so you need fflush(STDOUT)).

Quote:
Since the process B received all the 100 packets it gets killed.
What kills process B? Is it your ctrl-C/SIGINT?

Now to your actual question:
You can install a signal handler for SIGINT so that it does the normal thing after a small delay. For instance, one way to do this would be to have something like a signal handler that calls exit():
Code:
#include <signal.h>
void
sighandler(int thesignal) {
  signal(SIGINT,SIG_IGN);
  sleep(3);
  exit(2);
}

main() { 
 .... somehwere ...
 signal(SIGINT, sighandler);
 ... main code...
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to prevent process from being killed

Hi,all.Well,I know someone has already asked this question before,however,It's too long before.So i post a new thread here. Here is the issue.I have a shell script that use awk to calculate something and the script takes about 15 mins,it will use 100% CPU,and the system automatically killed the... (2 Replies)
Discussion started by: homeboy
2 Replies

2. UNIX for Dummies Questions & Answers

Process Killed : Need to find why ?

Hi reader, I'm making a tool out of korn shell script that is running on a HP-UX server. But everytime i invoke the tool, it gets killed after a while (mid-process). I have tried re-running it a couple of times but each invocation ending up the same way .. following is a snippet of the o/p... (8 Replies)
Discussion started by: clakkad
8 Replies

3. UNIX for Dummies Questions & Answers

Protect a Process from Being Killed

Hi, I have a process which takes 13-15 mins for execution and its getting killed in the meantime.So can you please helpme out how to protect the process from getting killed. Thanks in advance. Regards, Harika (9 Replies)
Discussion started by: harikagrp
9 Replies

4. UNIX for Dummies Questions & Answers

SAS Process Getting Killed

HI all, I am very new to AIX (matter of fact Unix). We are currently automating out manual process using Unix Shell Scripting. My wrote a shell script which will accept the name of the sas job as parameter, checks the existense of the sas file in the specified folder. If it is not present,... (1 Reply)
Discussion started by: anubhav2020
1 Replies

5. Solaris

LDAP process getting killed

Hi all, Currently I am using LDAP to store some network related data, When I run following script ./ns-slapd ldif2db Execution of above script terminates displaying "Killed" on the console. As far as I know, a process can be killed by two ways- 1. manually running " kill -9 <PID of LDAP... (1 Reply)
Discussion started by: akash_mahakode
1 Replies

6. Solaris

how to run a killed process

hi, i am creating a daemon process for updating the file at regular interval.one problem with this is if anybody kills the daemon it wont update the file.anybody have idea how to rerun the daemon if it killed.the code is written in c++ in solaries environment. thnaks & regards suresh (8 Replies)
Discussion started by: suresh_rtp
8 Replies

7. UNIX for Advanced & Expert Users

how to delay a process getting killed before it completes its work

The problem i am encountering is the process is getting killed before it dispalys the details.The details are displayed using printf.I created a new buffer for printing the details using setvbuf function call instead of output buffer.This is not working.The thing is,killing of the process must be... (1 Reply)
Discussion started by: cijkmysj
1 Replies

8. UNIX for Dummies Questions & Answers

Who is the parent of a killed process ?

Suppose we have the following process tree: init-> ProcessA->processB->processC then I kill processB Who is the parent of the processC? init or the processA (6 Replies)
Discussion started by: Puntino
6 Replies

9. Programming

Delay a process.

How to delay a process. I need to to delay a process from 3sec. At that 3sec other back ground processes also should stop. (just sit 3sec for idle & then starts execution as normally) I use sleep(3)-But it not stop the bg processes I try to use loop but it not gurantee to wait 3sec. ... (2 Replies)
Discussion started by: ugp
2 Replies

10. UNIX for Dummies Questions & Answers

process not getting killed

I have a process that is in the sleeping state "S" and I have tried to stop it with a run control script that I use to stop/start it - but it does not stop. I have tried kill -9 <PID of process> with no change. I imagine that this process is sleeping with the kernel. It does not respond to... (5 Replies)
Discussion started by: finster
5 Replies
Login or Register to Ask a Question