Sponsored Content
Top Forums Shell Programming and Scripting does the pid of background process show in /proc? Post 302491694 by homeboy on Friday 28th of January 2011 04:40:34 AM
Old 01-28-2011
does the pid of background process show in /proc?

Hi all,
I'm reading <advanced bash scripting> and there is a example to kill a background process in a limited time,as shown below:
Code:
#! /bin/bash

#set -n

TIMEOUT=$1
count=0

hanging_jobs & {
	while ((count < TIMEOUT));do
	   eval '[ ! -d "/proc/$!" ] && ((count = TIMEOUT))'
		((count++))
		sleep 1
		echo $!
	done

	eval '[ -d "/proc/$!" ] && kill -15 $! '
}

I don't know why it use eval (is it necessary?)and i can't understand the meaning of
Code:
[ ! -d "/proc/$!" ] && ((count = TIMEOUT))

besides,the book says that /proc is where information about running process is found,but i can't find the relative directory of my background process.why?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

PID of process started in background??

I am having a problem getting the PID of a process I start in the background is a csh. In tcsh and sh it's simple $! give it to you But in csh this just returns Variable syntax From the man page it should work but it doesn't???? Any help. (2 Replies)
Discussion started by: stilllooking
2 Replies

2. Red Hat

read maps from /proc/pid/

hi, i hav a query abt reading the contents of /proc/pid/maps file.is there any system apis or functions available to get the data from dat file and parse according to my need. i need name of the .so,Create date of the .so file.,Location of .so file etc. please provide a good source. yes i hav... (3 Replies)
Discussion started by: sanjaykhuntia
3 Replies

3. UNIX for Dummies Questions & Answers

Need to get pid of a process and have to store the pid in a variable

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

4. Shell Programming and Scripting

A question about the PID of a background function

Dear all, I'm writing a KornShell script that calls inside it a function in background mode #!/bin/ksh function myfunction { . . .} myfunction |& . . . How can I capture the PID of the function myfunction that runs in background? Thanks in advance :) (2 Replies)
Discussion started by: dariyoosh
2 Replies

5. Shell Programming and Scripting

kill PID running in background in for loop

Guys, can you help me in killing the process which is running in back ground under for loop I am not able to find the PID using ps -afx|grep <word in command I entered> (1 Reply)
Discussion started by: mohan_xunil
1 Replies

6. Shell Programming and Scripting

PID from background ssh

Hello. I was wondering if someone can help me out with something. To simplify my life, I have written a tiny script to open an ssh tunnel through another linux host so that I can access the esxi hosts on that network using the client. For this I have to tunnel ports 443, 902, and 903. Here is what... (1 Reply)
Discussion started by: numetheus
1 Replies

7. Shell Programming and Scripting

Background process, return code and pid.

Hey all, Okay, this one is tricky and I'm not sure there is a niec way to do it, or indeed anyway to do it. The main issue revolves around timing out a hung ssh. I am doing this by creating a wrapper script for the ssh with the following requirements. My requirements are: Defineable... (5 Replies)
Discussion started by: RECrerar
5 Replies

8. Shell Programming and Scripting

Closing open file descriptors from /proc/pid/fd

Hi guys, i need to write a shell script that will close file descriptors from /proc/pid/fd will calling exec 4<&- solve the problem ? thanks in advance :) (15 Replies)
Discussion started by: alpha_romeo
15 Replies

9. UNIX for Dummies Questions & Answers

/proc/pid/maps

I think the libc.so is shared between processes, because it is a shared library and OS is engaged for saving memory. But, below, the maps of bash, shows r-xp and r--p rw-p attributes to libc.so which mean private memory space. Can anybody explain this for me? :)cat /proc/$$/maps... (4 Replies)
Discussion started by: vistastar
4 Replies

10. Shell Programming and Scripting

[SOLVED] Using "$!" to get the PID of the Last Ran Background Process

Hello All, I was looking into creating a script that would be used only to start a Daemon and create a lock file... F.Y.I. It's for Nagios' NRPE Daemon Plugin... Anyway when I run the command to start the Daemon (below): /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d And... (14 Replies)
Discussion started by: mrm5102
14 Replies
VMSTAT(8)						   Linux Administrator's Manual 						 VMSTAT(8)

NAME
vmstat - Report virtual memory statistics SYNOPSIS
vmstat [-n] [delay [ count]] vmstat[-V] DESCRIPTION
vmstat reports information about processes, memory, paging, block IO, traps, and cpu activity. The first report produced gives averages since the last reboot. Additional reports give information on a sampling period of length delay. The process and memory reports are instantaneous in either case. Options The -n switch causes the header to be displayed only once rather than periodically. delay is the delay between updates in seconds. If no delay is specified, only one report is printed with the average values since boot. count is the number of updates. If no count is specified and delay is defined, count defaults to infinity. The -V switch results in displaying version information. FIELD DESCRIPTIONS
Procs r: The number of processes waiting for run time. b: The number of processes in uninterruptable sleep. w: The number of processes swapped out but otherwise runnable. This field is calculated, but Linux never desperation swaps. Memory swpd: the amount of virtual memory used (kB). free: the amount of idle memory (kB). buff: the amount of memory used as buffers (kB). Swap si: Amount of memory swapped in from disk (kB/s). so: Amount of memory swapped to disk (kB/s). IO bi: Blocks sent to a block device (blocks/s). bo: Blocks received from a block device (blocks/s). System in: The number of interrupts per second, including the clock. cs: The number of context switches per second. CPU These are percentages of total CPU time. us: user time sy: system time id: idle time NOTES
vmstat does not require special permissions. These reports are intended to help identify system bottlenecks. Linux vmstat does not count itself as a running process. All linux blocks are currently 1k, except for CD-ROM blocks which are 2k. FILES
/proc/meminfo /proc/stat /proc/*/stat SEE ALSO
ps(1), top(1), free(1) BUGS
Does not tabulate the block io per device or count the number of system calls. AUTHOR
Written by Henry Ware <al172@yfn.ysu.edu>. Throatwobbler Ginkgo Labs 27 July 1994 VMSTAT(8)
All times are GMT -4. The time now is 09:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy