I'm having some problems wiriting a program in UNIX using the "fork" and "kill" system calls.
I have to create a C program P0, which creates 9 other processes
P1, P2, ..., P9, where P0 is the father of P1, P1 the father of P2, and so on.
All the processes contain an infinite loop.
When all the processes are created P9 executes the command "ps".
Then P9 kills P8, execute "ps", then kills P7, executes "ps", and so
on till only the process P0 and P9 remain.
I've created the 9 processes in the following way:
P0 does a fork. The child process executes p1 and the parent process enters and infinite loop.
p1 to p8 do the same thing.
p9 then executes ps.
Up to here there are no problems, ps is executed and everything seems to be working fine, the PID and PPID are correct, and all the processes are marked as running.
The problem I have is how to kill the parents of p9.
I use the kill function, but for this I need the PID of the processes to kill.
How can this be found?
To see at least if the kill process does what's it supposed to do, I use the getppid() system call to retrieve the PID of process p9's father and loop it back from there (not very elegant but should work in theory).
With this pid I then use the kill function with the SIGKILL signal and the pid of the process to be killed.
The problem here is that only p8 gets killed while the rest of the processes keep running!
Therefore the process p9 does something like this:
Hello,
A little background on what we are doing first. We are running several applications from a CLI, and not all of them are fully functional. They do on occasion core dump, not a problem. We are running a service that takes a screen scrape of those apps and displays them in a more user... (5 Replies)
Hi everyone
i am very new to linux , working on bash shell.
I am trying to solve the given problem
1. Create a process and then create children using fork
2. Check the Status of the application for successful running.
3. Kill all the process(threads) except parent and first child... (2 Replies)
My question is, how do you fork only the parent processes in unix? For example how would I use the fork function to fork the parent process more than once and leave the children processes alone. This way I do not have children of children. The way I have it set up now it the parent process forks 3... (7 Replies)
I had issues with processes locking up. This script checks for processes and kills them if they are older than a certain time.
Its uses some functions you'll need to define or remove, like slog() which I use for logging, and is_running() which checks if this script is already running so you can... (0 Replies)
I have a bash script that has been used for months here at work for doing an SSH into other machines both Linux and Solaris and running a script on the remote machine. Recently I have started to noticed that things are being left being on the maching doing the SSH.
For example....
tivoli ... (1 Reply)
Hi all,
I am writing a script which calls other third party scripts that perform numerous actions. I have no control over these scripts.
My problem is, one of these scripts seems to execute and do what it is meant to do, but my calling / parent script always exits at that point. I need to... (4 Replies)
hi,
I want my program to fork a new process and then I want to kill the parent process. The parent program before dying will issue a SIGTERM to all its childs. Which eventually kills all Children.
I cant handle the SIGTERM at the child level.:(
What I was thinking of was the Parent... (3 Replies)
Is there a way to monitor certain processes and if they hang too long to kill them, but certain scripts which are expected to take a long time to let them go?
Thank you
Richard (4 Replies)
Hi all,
I have a shell script which calls other shell scripts, depending on the input.
Within a.sh, I have a command which calls b.sh (ie. ksh b.sh)
Normally, we use the exit function to terminate a shell. However, if I choose to call exit from b.sh, I will return to the parent shell who... (4 Replies)
Hi,
Am working on linux. while forking in a loop how to avoid the child process from forking..for example
int n = 5;
pid_t pid;
pid_t ch_pid;
/*exactly wanted to create n processes and not 2^n processes*/
for(i = 0; i < n;i++)
{
if(pid = fork())
{
/* parent... (4 Replies)