System should not kill the child process when parent id is 1


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting System should not kill the child process when parent id is 1
# 1  
Old 01-26-2017
System should not kill the child process when parent id is 1

HI i would like to know how i can simulate a shell scripts for my requirement.

example
Code:
Server name child Process id Parent Process id 
Vpesh          16013              15637   
Server name child Process id Parent Process id 
Vpesh          16014              15637   
Server name child Process id Parent Process id 
Vpesh          16015              15638
Server name child Process id Parent Process id 
Vpesh          16016              15638

Most of the time we restart our server by killing child processes ids , so processes will come again with new child id and parent id . My requirement is - When Parent Process id is 1 that time system should not kill the child processes , it should display one msg" Parent Process id is 1 , you should kill this process" .
How can i simulate this ?

This is simple command i wrote to kill only child processes ids but it doesn't look for parent id .. so whenever parent id is 1 , this command is killing child processes .which is not acceptable .
Code:
kill -9 `ps -ef | grep processes | grep -v grep | awk '{print $2}'`

Thank
Vaibhav


Moderator's Comments:
Mod Comment Welcome, please use code tags next time for your code and data, thanks

Last edited by vbe; 01-26-2017 at 02:33 PM.. Reason: code tags
# 2  
Old 01-26-2017
Welcome to the forum!

With that little context it is difficult to give really valuable advice accounting for all sort of possible caveats. Modifying / improving ONLY your given pipe to include your request, try:
Code:
ps -ef | awk '/[p]rocesses/ && $3 != 1 {print $2}'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Kill Parent/ Child processes

I am trying to kill PIDs that are tied to a KSH "load_sqlplus" and I am using the below code LIST_PID=`ps -ef | grep -i "load_sqlplus" | grep -v grep | awk '{print $2}'` if ; then echo "Processes killed" "PID : " $LIST_PID kill -9 $LIST_PID else echo "Nothing to Kill" fi... (4 Replies)
Discussion started by: venky338
4 Replies

2. Shell Programming and Scripting

forking a child process and kill its parent to show that child process has init() as its parent

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)
Discussion started by: vizz_k
2 Replies

3. Emergency UNIX and Linux Support

signal between parent process and child process

Hello, everyone. Here's a program: pid_t pid = fork(); if (0 == pid) // child process { execvp ...; } I send a signal (such as SIGINT) to the parent process, the child process receive the signal as well as the parent process. However I don't want to child process to receive the... (7 Replies)
Discussion started by: jackliang
7 Replies

4. Programming

Parent process starts before the child using signal, in C

Hi, i want that the parent process start before the child, this code doesn't work, if the child start before the parent it wait for signal, then the father send the signal SIGALRM and the child catch it and call printf; else the father call printf and send the signal to the child that call its... (1 Reply)
Discussion started by: blob84
1 Replies

5. UNIX for Dummies Questions & Answers

Command to find parent and child process?

Hi, I have a script that calls other scripts/commands which may or may not spawn other process. From my understanding, when I do a ps -ef, the highest numbered process ID is supposed to be the parent ID of all the other related child processes, is this correct? In most or all... (3 Replies)
Discussion started by: newbie_01
3 Replies

6. Shell Programming and Scripting

[KSH/Bash] Starting a parent process from a child process?

Hey all, I need to launch a script from within 2 other scripts that can run independently of the two parent scripts... Im having a hard time doing this, if anyone knows how please let me know. More detail. ScriptA (bash), ScriptB (ksh), ScriptC (bash) ScriptA, launches ScriptB ScirptB,... (7 Replies)
Discussion started by: trey85stang
7 Replies

7. Shell Programming and Scripting

How to make the parent process to wait for the child process

Hi All, I have two ksh script. 1st script calls the 2nd script and the second script calls an 'C' program. I want 1st script to wait until the 'C' program completes. I cant able to get the process id for the 'C' program (child process) to make the 1st script to wait for the second... (7 Replies)
Discussion started by: sennidurai
7 Replies

8. Programming

Implementing 2 pipes between a parent and child process

Hi all, I'm trying to write a program that has some data it wants to send through a filter program(in this case tr), and then recieve the output from that filter program. The way I'm trying to do it is by setting up two pipes between the programs and piping the data in through one pipe and back... (2 Replies)
Discussion started by: bwgoudey
2 Replies

9. Programming

parent and child process question?

Hi everybody, I'm trying to understand how a parent and child processes interact. This function( below) basically measures the fork time from the perspective of the parent only. what i would like to know is how to measure the time from the perspective of parent and child (ie: inserting... (0 Replies)
Discussion started by: tosa
0 Replies

10. UNIX for Dummies Questions & Answers

kill parent and child

Hello all, I have gone through the search and looked at posting about idle users and killing processes. Here is my question I would like to kill an idle user ( which I can do) but how can I asure that all of his process is also killed whit out tracing his inital start PID. I have tried this on a... (4 Replies)
Discussion started by: larry
4 Replies
Login or Register to Ask a Question