AIX > Tips & Techniques > Systems Management

Processes and Devices—It’s All About the Children


Within the AIX (or Linux) world, if a process is spawned, a copy of the parent process is used and the child process is created. Spawning children is a quick and effective way of handling many tasks that a process might have to undertake. When a parent is terminated or stopped, its children should be terminated in a controlled manner. This is the responsibility of the parent process, however, this doesn’t always happen. It’s important to know what children are associated with what parent, in case you’re faced with processes you might need to kill. You must keep track of the children and the parent. Here, I’ll demonstrate a couple of ways this can be achieved when dealing with the children method.

AIX uses a top-down approach to represent its devices using the parent/children method, a sort of device tree if you like. There is a hierarchy on each device, whether it’s physical or logical. When making changes to devices you cannot just jump in and use rmdev on devices. You need to know which devices hang off what slot. For example, if you wanted to remove or make a change to a fibre card, like fscsi, you must first remove or make unavailable any device hanging off that device. I will demonstrate how AIX sees children and its parent regarding devices using a few commands.

Keep an Eye on Those Children

For ease of identification, a script called trickle will be executed; it will spawn two children: trickle1, trickle2, like so:

#  ps -ef -o user,pid,ppid,args|grep trickle
    root 5701778 5373994 /bin/sh /home/dxtans/trickle
    root 5898334 5701778 /bin/sh /home/dxtans/trickle2
    root 8650902 5701778 /bin/sh /home/dxtans/trickle1

Notice that the main process parent’s PID is 5701778; and the PPID for the children is 5701778. Once a parent spawns, its children will inherit the parent PID into their own PPID. To locate a parent and all of its children, first find the PID of the main process, and with that PID use ps with grep to locate its children. Alternatively, you can use the -T option with the ps command to display the process and its children, if present, like so:

# ps -fT 5701778
     UID     PID    PPID   C    STIME    TTY  TIME CMD
    root 5701778 5373994   0 12:57:15      -  0:00 /bin/sh /home/dxtans/trickle
    root 5898334 5701778   0 12:57:15      -  0:00    |\--/bin/sh /home/dxtans/trickle2
    root 7471214 5898334   0 12:57:15      -  0:00    |    \--scan 60
    root 8650902 5701778   0 12:57:15      -  0:00     \--/bin/sh /home/dxtans/trickle1
    root 6684866 8650902   0 12:57:15      -  0:00         \--scan 60

Parsing the ps command with the PID will then display the parent and its children and any other process the children are executing. From the output above, we can see that each child is running a utility called scan. However an even better visual for detecting child processes involves the proctree command. Simply parse it with the PID, like so:

#  proctree -T -a 5701778
1             \--/etc/init
6815968             \--/usr/sbin/cron
5373994                   \--ksh
5701778                         \--/bin/sh /home/dxtans/trickle
5898334            |     |     |     |\--/bin/sh /home/dxtans/trickle2
7471214            |     |     |     |      \--scan 60
8650902            |     |     |     |\--/bin/sh /home/dxtans/trickle1
6684866            |     |     |     |      \--scan 60

The output here indicates the process was activated via cron, whose parent is init. While not in this output, the PPIDs are shown within a text display for easier identification, in my opinion.

As noted, when terminating a parent process with children, the parent should then terminate its own children. Otherwise, they’ll be orphaned, and init will be their parent. Let’s see that in action now:

# kill -9 5701778
#  ps -ef -o user,pid,ppid,args|grep trickle
    root 5898334       1 /bin/sh /home/dxtans/trickle2
    root 8650902       1 /bin/sh /home/dxtans/trickle1

A kill -9 (absolute kill) has been executed against the parent, but the children remain as the children of init (1). These remaining processes will need to be killed manually. If you don’t clean up these processes, you’re asking for trouble down the line when restarting the process or service. At best, you’ll have a lot of orphans whose parent is init. At worst, the process, if restarted, might compete for allocated resources, which isn't good. When a parent process is terminated, make sure the children are as well.

David Tansley is a freelance writer and an IBM Champion.



Like what you just read? To receive technical tips and articles directly in your inbox twice per month, sign up for the EXTRA e-newsletter here.


comments powered by Disqus
Buyers Guide

Advertisement

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link iPad App Google Play Store

Advertisement