10-26-2001
Obtaining A Process ID (PID)
Is there any way I can get UNIX to return the Process ID of a process when I actually issue the command to invoke the process?
For example, if I was to launch an emacs process in batch mode, by issuing the UNIX command :
% emacs file.txt&
then UNIX would return the Process ID (PID). "2343", for example.
Is this possible?
The reason I ask this question is because I am invoking programs from a remote machine and need to periodically probe for which processes are running to see whether the processes are still running or if they have terminated.
I suppose I could just issue a 'ps' command, pipe the output to a file and then grep the file for the commands issued, but the processes I am looking for depend on the directory they were invoked from and I don't think the 'ps' utility records the directory which a program/process was executed from - or does it?
Many thanks!
10 More Discussions You Might Find Interesting
1. Programming
I have written a program to collect some performance metrics on and AIX box, but I'm having difficultly getting the process information.
I'm lead to believe that I'm not getting the correct information because I'm trying to run the program on AIX 5.1 (5100-03), but I'm not convinced as the... (0 Replies)
Discussion started by: StuBob
0 Replies
2. Shell Programming and Scripting
Hi Friends :p
I have a little problem please help me out. I have a Unix based OS Sun Server having oracle 8i as database on it. The server has one client with windows OS. The client uses developer 2000 (GUI) to run query and run processes. I want to know how can I know the PID of a process run... (3 Replies)
Discussion started by: vanand420
3 Replies
3. Solaris
hi all,
Is there a simple script anyone could through out to me, to find the pid of a process given the name. I actually need to bind this pid to a processor set. I would probably put these comamns in a shell script which would have.
a) kick start the executable
b) get the pid
c) bind it to a... (10 Replies)
Discussion started by: Naanu
10 Replies
4. Linux
I am trying to submit a background process on a remote machine using
ssh -f remote-host "sh my-process.sh"
Normally the process will be submitted and control returned to the local machine (even when the process is running on the remote machine)
I want to get the process id of the submitted... (4 Replies)
Discussion started by: superuser84
4 Replies
5. UNIX for Dummies Questions & Answers
Hi,
I need to get the pid of a process and have to store the pid in a variable and i want to use this value(pid) of the variable for some process. Please can anyone tell me how to get the pid of a process and store it in a variable. please help me on this.
Thanks in advance,
Amudha (7 Replies)
Discussion started by: samudha
7 Replies
6. Shell Programming and Scripting
Hi
I have written a shell script to find and kill the particular process. Here in shell script i have written the code like
cnt = $(ps -ef | grep Shree)
echo $cnt
I am getting the output
root 2326 2317 0 14:39:46 pts/1 0:28 Shree -f fdc.fbconf FDCapp.fbapp
Here I want to... (2 Replies)
Discussion started by: Shreedhar Naik
2 Replies
7. Shell Programming and Scripting
Hi all,
i was able to redirect pid of process to a file in the following way
ps aux|awk '$11 == "/Applications/ProjectX/DServer" >> /Applications/ProjectX/DServer.pid
it works fine but if one folder name caontains space its not working like below
ps aux|awk '$11 == "/Applications/Project\... (1 Reply)
Discussion started by: kirankumars
1 Replies
8. Programming
Hi
I use linux OS.
I've already written a function that allow me to get the process name by pid. (searching in /proc). Now I'd like to perform the inverse task.I mean get the process pid by its name.
I could write a function that search in every folder in /proc for the process name, but i... (2 Replies)
Discussion started by: Dedalus
2 Replies
9. AIX
Hi
I would like to know more about swapper process..
I knew that swapper is the first process with PID#0, used to perform process swap operations. It used to swap entire processes
But sometimes I find swapper process with PID#264
So my doubt is how many swapper process can exist in a system?... (2 Replies)
Discussion started by: Priya Amaresh
2 Replies
10. AIX
HI,
i used
ps -ef | grep 3539052 | grep -v grep
and i got a output like ths
root 3539052 3407918 0 May 07 - 709:31 /usr/sbin/syslogd
but what i need is instead of full path /usr/sbin/syslogd i want only the process name that is 'syslogd' here. (3 Replies)
Discussion started by: sumanthupar
3 Replies
system(3S) system(3S)
NAME
system() - issue a shell command
SYNOPSIS
DESCRIPTION
executes the command specified by the string pointed to by command. The environment of the executed command is as if a child process were
created using (see fork(2)), and the child process invoked the sh-posix(1) utility via a call to (see exec(2)) as follows:
ignores the and signals, and blocks the signal, while waiting for the command to terminate. If this might cause the application to miss a
signal that would have killed it, the application should examine the return value from and take whatever action is appropriate to the
application if the command terminated due to receipt of a signal.
does not affect the termination status of any child of the calling processes other than the process or processes it itself creates.
does not return until the child process has terminated.
APPLICATION USAGE
If the return value of is not -1, its value can be decoded through the use of the macros described in For convenience, these macros are
also provided in
Note that, while must ignore and and block while waiting for the child to terminate, the handling of signals in the executed command is as
specified by fork(2) and exec(2). For example, if is being caught or is set to when is called, the child is started with handling set to
Ignoring and in the parent process prevents coordination problems (such as two processes reading from the same terminal) when the executed
command ignores or catches one of the signals.
RETURN VALUE
If command is null, returns non-zero.
If command is not null, returns the termination status of the command language interpreter in the format specified by wait(2). The termi-
nation status of the command language interpreter is as specified for sh-posix(1), except that if some error prevents the command language
interpreter from executing after the child process is created, the return value from is as if the command language interpreter had termi-
nated using If a child process cannot be created, or if the termination status for the command language interpreter cannot be obtained,
returns -1 and sets to indicate the error.
DIAGNOSTICS
forks to create a child process which, in turn, in order to execute string. If the fork fails, returns -1 and sets If the exec fails,
returns the status value returned by (see wait(2)) for a process that terminates with a call of
ERRORS
If errors are encountered, sets values as described by fork(2).
FILES
SEE ALSO
sh(1), fork(2), exec(2), wait(2), thread_safety(5).
STANDARDS CONFORMANCE
system(3S)