Sponsored Content
Full Discussion: Parent/Child Processes
Top Forums Shell Programming and Scripting Parent/Child Processes Post 302075180 by yoi2hot4ya on Wednesday 31st of May 2006 11:42:58 AM
Old 05-31-2006
Parent/Child Processes

Hello.
I have a global function name func1() that I am sourcing in from script A. I call the function from script B. Is there a way to find out which script called func1() dynamically so that the func1() can report it in the event there are errors?

Thanks
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

what are parent and child processes all about?

I don't follow what these are... this is what my text says... "When a process is started, a duplicate of that process is created. This new process is called the child and the process that created it is called the parent. The child process then replaces the copy for the code the parent... (1 Reply)
Discussion started by: xyyz
1 Replies

2. Filesystems, Disks and Memory

How hard can it be? ps child/parent

:( Since I'm fairly new to the scene and don't have much experience in shell programming, I decided to check out the net for a useful script or two. What I'm looking for is a script that would let me enter a PID and then show the process tree associated with it. So it would display the (grand-)... (2 Replies)
Discussion started by: velde046
2 Replies

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

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

5. UNIX for Dummies Questions & Answers

Kill child processes, when parent is "bash"

Consider this simple command line bash -c 'echo $$ ; sleep 10000'This will print the newly created bash PID and sleep for a long time. If I go to another terminal and do something like ps -flax | grep leepI'll see something like 501 92418 91910 0 0:00.00 ttys000 0:00.00 bash -c echo $$... (5 Replies)
Discussion started by: teras
5 Replies

6. Shell Programming and Scripting

Creating a pipe using parent and child processes

Hello, I am trying to create a pipe that will direct stdout to in side of the pipe, and stdin to the out side of the pipe - I created two child processes to handle this. However, my pipe doesn't seem to be working correctly. Did I use execv() correctly? Command1 and command2 represent the two... (3 Replies)
Discussion started by: jre247
3 Replies

7. Homework & Coursework Questions

Need help with deleting childīs parent and child subprocess

1. The problem statement, all variables and given/known data: I need to make an program that in a loop creates one parent and five children with fork(). The problem i'm trying to solve is how to delete the parent and child of the childīs process. 2. Relevant commands, code, scripts,... (0 Replies)
Discussion started by: WhiteFace
0 Replies

8. Programming

fork(), parent and child processes???

Hi friends, I have a small question regarding unix system call fork, I hope you will solve my problem. Here is the small program $ cat fork1.c #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { int pid; int x = 0; x = x + 1; pid = fork(); if(pid < 0) {... (2 Replies)
Discussion started by: gabam
2 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

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
MAKECONTEXT(3)						     Linux Programmer's Manual						    MAKECONTEXT(3)

NAME
makecontext, swapcontext - manipulate user context SYNOPSIS
#include <ucontext.h> void makecontext(ucontext_t *ucp, void (*func)(), int argc, ...); int swapcontext(ucontext_t *oucp, ucontext_t *ucp); DESCRIPTION
In a System V-like environment, one has the type ucontext_t defined in <ucontext.h> and the four functions getcontext(3), setcontext(3), makecontext() and swapcontext() that allow user-level context switching between multiple threads of control within a process. For the type and the first two functions, see getcontext(3). The makecontext() function modifies the context pointed to by ucp (which was obtained from a call to getcontext(3)). Before invoking make- context(), the caller must allocate a new stack for this context and assign its address to ucp->uc_stack, and define a successor context and assign its address to ucp->uc_link. When this context is later activated (using setcontext(3) or swapcontext()) the function func is called, and passed the series of integer (int) arguments that follow argc; the caller must specify the number of these arguments in argc. When this function returns, the successor context is activated. If the successor context pointer is NULL, the thread exits. The swapcontext() function saves the current context in the structure pointed to by oucp, and then activates the context pointed to by ucp. RETURN VALUE
When successful, swapcontext() does not return. (But we may return later, in case oucp is activated, in which case it looks like swapcon- text() returns 0.) On error, swapcontext() returns -1 and sets errno appropriately. ERRORS
ENOMEM Insufficient stack space left. VERSIONS
makecontext() and swapcontext() are provided in glibc since version 2.1. CONFORMING TO
SUSv2, POSIX.1-2001. POSIX.1-2008 removes the specifications of makecontext() and swapcontext(), citing portability issues, and recommend- ing that applications be rewritten to use POSIX threads instead. NOTES
The interpretation of ucp->uc_stack is just as in sigaltstack(2), namely, this struct contains the start and length of a memory area to be used as the stack, regardless of the direction of growth of the stack. Thus, it is not necessary for the user program to worry about this direction. On architectures where int and pointer types are the same size (e.g., x86-32, where both types are 32 bits), you may be able to get away with passing pointers as arguments to makecontext() following argc. However, doing this is not guaranteed to be portable, is undefined according to the standards, and won't work on architectures where pointers are larger than ints. Nevertheless, starting with version 2.8, glibc makes some changes to makecontext(), to permit this on some 64-bit architectures (e.g., x86-64). EXAMPLE
The example program below demonstrates the use of getcontext(3), makecontext(), and swapcontext(). Running the program produces the fol- lowing output: $ ./a.out main: swapcontext(&uctx_main, &uctx_func2) func2: started func2: swapcontext(&uctx_func2, &uctx_func1) func1: started func1: swapcontext(&uctx_func1, &uctx_func2) func2: returning func1: returning main: exiting Program source #include <ucontext.h> #include <stdio.h> #include <stdlib.h> static ucontext_t uctx_main, uctx_func1, uctx_func2; #define handle_error(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0) static void func1(void) { printf("func1: started "); printf("func1: swapcontext(&uctx_func1, &uctx_func2) "); if (swapcontext(&uctx_func1, &uctx_func2) == -1) handle_error("swapcontext"); printf("func1: returning "); } static void func2(void) { printf("func2: started "); printf("func2: swapcontext(&uctx_func2, &uctx_func1) "); if (swapcontext(&uctx_func2, &uctx_func1) == -1) handle_error("swapcontext"); printf("func2: returning "); } int main(int argc, char *argv[]) { char func1_stack[16384]; char func2_stack[16384]; if (getcontext(&uctx_func1) == -1) handle_error("getcontext"); uctx_func1.uc_stack.ss_sp = func1_stack; uctx_func1.uc_stack.ss_size = sizeof(func1_stack); uctx_func1.uc_link = &uctx_main; makecontext(&uctx_func1, func1, 0); if (getcontext(&uctx_func2) == -1) handle_error("getcontext"); uctx_func2.uc_stack.ss_sp = func2_stack; uctx_func2.uc_stack.ss_size = sizeof(func2_stack); /* Successor context is f1(), unless argc > 1 */ uctx_func2.uc_link = (argc > 1) ? NULL : &uctx_func1; makecontext(&uctx_func2, func2, 0); printf("main: swapcontext(&uctx_main, &uctx_func2) "); if (swapcontext(&uctx_main, &uctx_func2) == -1) handle_error("swapcontext"); printf("main: exiting "); exit(EXIT_SUCCESS); } SEE ALSO
sigaction(2), sigaltstack(2), sigprocmask(2), getcontext(3), sigsetjmp(3) COLOPHON
This page is part of release 3.53 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
2013-02-12 MAKECONTEXT(3)
All times are GMT -4. The time now is 10:15 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy