Sponsored Content
Top Forums Programming Process creation in Unix with C Program Post 302332420 by dsudipta on Thursday 9th of July 2009 05:27:08 AM
Old 07-09-2009
Process creation in Unix with C Program

Hi,

can somebody please help me regarding this?
How can i print parent's PID from child's and vice versa.

I have tried with getpid() & ngetppid() function but it is not giving me the correct data. The logic i used is:

if (pid == 0)
{
getpid() : Chil'd PID
getppid(): Parent;s PID
}
else
{
getpid(): Parent's PID;
pid: Child' PID;
}

Output should match, right? But is is not matching.

If you have idea, please let me know.

With regards,
Sudipta
 

10 More Discussions You Might Find Interesting

1. HP-UX

IO by Process/program

HI there, I'm trying to find a way of showing the IO's performed by individual programs. Number of reads/writes IO time that kind of thing. Anybody know of any way to show this information. Free little downloads that kind of thing? Cheers Phil (2 Replies)
Discussion started by: cpiuk
2 Replies

2. HP-UX

get program name give a process id

Hi , I have query regarding to get a program name given a pid in HP-Ux . give procees id ( PID) i would like to retrieve the process/program through a C program ? my input to c program will be will be pid and i would like to know what is process name /program name . Many Thanks ... (1 Reply)
Discussion started by: naren_chella
1 Replies

3. Programming

Getting process info in a program

Hi, I am wondering if there is a way to find out in a C software program if a particular process is running without having to write a file. In the past, I have been using the system command to execute a pgrep and output the info to a file. Then the C program reads the file to make the... (1 Reply)
Discussion started by: herbmiller
1 Replies

4. UNIX for Dummies Questions & Answers

how to Decrease priority of a particular process in time of process creation

how to decrease priority of a particular process in time of process creation... and also how to decrease priority of a particular process after process creation.. can any one please help me out... (2 Replies)
Discussion started by: Ramkum
2 Replies

5. Programming

Process creation

I want to execute an application from my c code. I am using system call to run it. But sytem call is blocking, because it waiting to die that application. Therefore, my running application is hanging. I don't want to use the fork. Is there any way to do it. Windows is providing CreateProcess... (1 Reply)
Discussion started by: Saurabh78
1 Replies

6. Shell Programming and Scripting

Help for makefile creation in Unix

Hello, I had created a makefile for my simple C application. I am able to create object and library file through makefile sucessfully. I had written a code snippet for executable file also, but somehow its not working. Here is the code for executable in makefile: $(BIN)/EXT: $(OBJ)/EXT.o... (0 Replies)
Discussion started by: Poonamol
0 Replies

7. Shell Programming and Scripting

Process Creation

how the fork function creats the child process????? what the things it will take from parent process nd what it will give to child process? (4 Replies)
Discussion started by: Mac91
4 Replies

8. Shell Programming and Scripting

Bash script to Automate the Virtual Host creation process!!

Hi all, This is my sample code in /etc/httpd/conf.d/applications.conf file currently we are creating subdomain mannually for every new subdomain. I want to automate this process througs bash script , how its possible. <VirtualHost *:80> ServerName google.com ServerAlias google.com... (5 Replies)
Discussion started by: anishkumarv
5 Replies

9. Shell Programming and Scripting

How can I get parent process program name?

Hi: I have 2 script on AIX server. The child script is called by parent script. For example: The parent script full name is /home/op/def/parent.spt, which calls /home/op/abc/child.spt I want to get the parent program name with full path name (i.e. /home/op/def/parent.spt), in... (3 Replies)
Discussion started by: cstsang
3 Replies

10. Shell Programming and Scripting

How to write program that find winner who choose the smallest number. UNIX process?

In the game of “Unique”, multiple players privately choose an integer. They then reveal their choice. The winner is the player who chose the smallest unique number. The game is considered a draw if no unique integer was chosen. You would write a program that simulate such a game according to the... (1 Reply)
Discussion started by: dantesma
1 Replies
GETPID(2)						     Linux Programmer's Manual							 GETPID(2)

NAME
getpid, getppid - get process identification SYNOPSIS
#include <sys/types.h> #include <unistd.h> pid_t getpid(void); pid_t getppid(void); DESCRIPTION
getpid() returns the process ID of the calling process. (This is often used by routines that generate unique temporary filenames.) getppid() returns the process ID of the parent of the calling process. ERRORS
These functions are always successful. CONFORMING TO
POSIX.1-2001, 4.3BSD, SVr4. NOTES
Since glibc version 2.3.4, the glibc wrapper function for getpid() caches PIDs, so as to avoid additional system calls when a process calls getpid() repeatedly. Normally this caching is invisible, but its correct operation relies on support in the wrapper functions for fork(2), vfork(2), and clone(2): if an application bypasses the glibc wrappers for these system calls by using syscall(2), then a call to getpid() in the child will return the wrong value (to be precise: it will return the PID of the parent process). See also clone(2) for discussion of a case where getpid() may return the wrong value even when invoking clone(2) via the glibc wrapper function. SEE ALSO
clone(2), fork(2), kill(2), exec(3), mkstemp(3), tempnam(3), tmpfile(3), tmpnam(3), credentials(7) 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/. Linux 2008-09-23 GETPID(2)
All times are GMT -4. The time now is 09:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy