Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Command to find parent and child process? Post 302515880 by Skrynesaver on Thursday 21st of April 2011 06:14:00 AM
Old 04-21-2011
You're incorrect in your reasoning, the output shows a clear inheritance tree. For your own enlightenment try the following
Code:
ps -ef | egrep  '^ *(UID|exp)' | grep -v grep

The first line of the ps -ef output lets you know the contents of the column below each title.
Code:
UID        PID  PPID  C STIME TTY          TIME CMD

PPID is the parent process ID , so you could check for your PID in the 3rd column (assuming GNU or SunOS ps here) and report the second column if true.
The following will return all process spawned by init (PID=1)
Code:
ps -ef | awk '{if ($3 == 1) print $2 ": " $8;}'


Last edited by Skrynesaver; 04-21-2011 at 11:19 AM.. Reason: Added awk example
 

10 More Discussions You Might Find Interesting

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

2. Programming

display in a child process a command called in the parent one

Hi , Could you tell me if I am right 1. Using fork(), pipe(), execlp() and dup() (see man 2 dup), write a C program executing the command ps -j in a parent process, displaying the result in a child process. #include <unistd.h> #include <errno.h> #include <stdio.h> #include <unistd.h>... (7 Replies)
Discussion started by: remid1985
7 Replies

3. UNIX for Advanced & Expert Users

How to find all the child processes of a parent process

Hi I am trying to see if there are some options in ps command or if there is a shell script which basically shows you all the processes spawned by a parent process , then all the processes of its child processes and so on down the hierarchy may be like a tree structure. It might be a generic... (6 Replies)
Discussion started by: clifford
6 Replies

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

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

6. Programming

IPC - pipes between parent and child process

Hi guys, I'm having some problem here, I'm studying pipes, and i want to create a shell in C and at this point a don't want to use semaphores, instead I want to use tricks. Straight to the doubt: I've a parent and a child process, and both of them has some code to execute, and the child process... (5 Replies)
Discussion started by: pharaoh
5 Replies

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

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

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

10. Shell Programming and Scripting

How make parent to wait from child process?

Hi all, I am starting mgen5 for sometime depends on input from a file, in a child process. now I want to make parent to wait in this child process till mgen5 finishes, or timeout happens. could anyone please tell me how to make parent to wait in child process in shell script? thanks... (2 Replies)
Discussion started by: girijajoshi
2 Replies
POSIX_SPAWNATTR_SETFLAGS(3)				   BSD Library Functions Manual 			       POSIX_SPAWNATTR_SETFLAGS(3)

NAME
posix_spawnattr_setflags posix_spawnattr_getflags -- get or set flags on a posix_spawnattr_t SYNOPSIS
#include <spawn.h> int posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags); int posix_spawnattr_getflags(const posix_spawnattr_t *restrict attr, short *restrict flags); DESCRIPTION
The posix_spawnattr_setflags() function sets the flags on the attributes object referenced by attr. The posix_spawnattr_getflags() function retrieves the flags on the attributes object referenced by attr. The argument flags is either 0 or a logical OR of one or more of the following flags: POSIX_SPAWN_RESETIDS If this bit is set, the child process will inherit the real (rather than the effective) user and group ID of the parent process. NOTE: This flag has no effect when the set-group bit is set on the process image being spawned. POSIX_SPAWN_SETPGROUP If this bit is not set, then the child process inherits the parent process group; if it is set, then the child process will behave as if the setpgid(2) function had been called with a pid parameter of 0 and a pgid parameter equal to the value of the spawn-pgroup value of the posix_spawnattr_t, as set by posix_spawnattr_setpgroup(3) POSIX_SPAWN_SETSIGDEF Signals set to either be caught or to the default action in the parent process will also be set to the default action in the child process. Signals set to be ignored in the parent process will be ignored in the child. However, if this bit is set, then signals in the spawn-sigdefault value of the posix_spawnattr_t, as set by posix_spawnattr_setsigdefault(3) which are caught or ignored in the parent will instead be reset to their default actions in the child. POSIX_SPAWN_SETSIGMASK If this bit is set, then the initial signal mask of the child process will be set to the spawn-sigmask value of the posix_spawnattr_t, as set by posix_spawnattr_setsigmask(3). POSIX_SPAWN_SETEXEC Apple Extension: If this bit is set, rather than returning to the caller, posix_spawn(2) and posix_spawnp(2) will behave as a more featureful execve(2). POSIX_SPAWN_START_SUSPENDED Apple Extension: If this bit is set, then the child process will be created as if it immediately received a SIGSTOP signal, permitting debuggers, profilers, and other programs to manipulate the process before it begins execution in user space. This permits, for example, obtaining exact instruction counts, or debugging very early in dyld(1). To resume the child process, it must be sent a SIGCONT signal. POSIX_SPAWN_CLOEXEC_DEFAULT Apple Extension: If this bit is set, then only file descriptors explicitly described by the file_actions argu- ment are available in the spawned process; all of the other file descriptors are automatically closed in the spawned process. RETURN VALUES
On success, these functions return 0; on failure they return an error number from <errno.h>. The posix_spawnattr_getflags() function addi- tionally, upon successful completion, makes the value pointed to by the flags argument equal to the spawn-flags attribute of the posix_spawnattr_t. ERRORS
These functions may fail if: [EINVAL] The value specified by attr is invalid. [EINVAL] The value of attr is invalid. SEE ALSO
posix_spawn(2), posix_spawnp(2), posix_spawnattr_init(3), posix_spawnattr_destroy(3), posix_spawnattr_setpgroup(3), posix_spawnattr_setsigdefault(3), posix_spawnattr_setsigmask(3), posix_spawn_file_actions_init(3), setpgid(2), signal(3), execve(2), dyld(1) STANDARDS
Version 3 of the Single UNIX Specification (``SUSv3'') [SPN] HISTORY
The posix_spawnattr_setflags() and posix_spawnattr_getflags() function calls appeared in Version 3 of the Single UNIX Specification (``SUSv3'') [SPN]. Mac OS X October 28, 2010 Mac OS X
All times are GMT -4. The time now is 05:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy