Re: one process, different PID



within the list of parameter declarations in a function prototype (not part
of a function

definition), the identifier has function prototype scope, which terminates
at the end of the

function declarator. If an identifier designates two different entities in
the same name

space, the scopes might overlap. If so, the scope of one entity (the inner
scope) will be a

strict subset of the scope of the other entity (the outer scope). Within the
inner scope, the

identifier designates the entity declared in the inner scope; the entity
declared in the outer

scope is hidden (and not visible) within the inner scope.

5 Unless explicitly stated otherwise, where this International Standard uses
the term

??identifier?? to refer to some entity (as opposed to the syntactic
construct), it refers to the

entity in the relevant name space whose declaration is visible at the point
the identifier

occurs.

6 Two identifiers have the same scope if and only if their scopes terminate
at the same

point.

7 Structure, union, and enumeration tags have scope that begins just after
the appearance of

the tag in a type specifier that declares the tag. Each enumeration constant
has scope that

begins just after the appearance of its defining enumerator in an enumerator
list. Any

other identifier has scope that begins just after the completion of its
declarator.

Joachim Schmitz wrote:
NBaH wrote:
On 26 juin, 15:56, NBaH <n_b_a_...@xxxxxxxxxx> wrote:
On 26 juin, 15:37, "Joachim Schmitz"
<nospam.j...@xxxxxxxxxxxxxxxxxx> wrote:



NBaH wrote:
Hello world !

As I intend to suspend a daemon I wrote
$~ cat /usr/sbin/diva
#!/bin/bash

# DIVA
## stands for: Disconnects Idle Virtual_terminals Automatically

export LC_TIME=C

pidof -x $0 >/var/run/$(basename $0).pid

Why not simply
echo $$ >/var/run/$(basename $0).pid

while :
do
idle_tty2stop=$(who -u | awk -F" " '$6 ~/5$/ { print $7 }')
tty2watch=$(who -u | awk -F" " '$6 ~/5$/ { print $6 }' | cut -d:
- f2)
for i in $tty2watch; do
[ $tty2watch -gt "4" ] && tput reset
kill -s TERM $idle_tty2stop > /dev/null 2>&1
done
sleep 60
done &
$~

I adapted the /etc/init.d/skeleton.

Daemon works fine at boot, and disconnects idle TTYs after 5mn.

But, as I want to stop it by typing `/etc/init.d/diva stop`, it
doesn't stop, because the value in /var/run/diva.pid is not
correct : $~ pidof -x /usr/sbin/diva
$~ 3330
$~ cat /var/run/diva.pid
$~ 3328

Does anybody have a clue to solve this trouble? Thanks

Bye, Jojo

It's the same... I first tried `echo $$` which provides the
behaviour I described, so I tried `pidof` with the same effect, and
I let the script in this state.

OK! I found the solution: it's the "done &" stuff at the end of the /
usr/sbin/diva's script. I removed the "&", placed "--background" in
the do_start function of /etc/init.d/skeleton-like script.

Now, pidof -x /usr/sbin/diva and cat /var/run/diva.pid are the same.
Ah, yes, sorry, I noticed that & and was about to tell you about it
but got distratcted...
Another possuble fix would be to use
echo $! >/var/run/$(basename $0).pid
after (!) the "done &", as that's the time at which the PID of that
background process is know

Bye, Jojo


.



Relevant Pages

  • Re: types, variable names and fields
    ... No, assuming the same scope, no two typedefs, objects, or functions ... determine what declaration an identifier refers to. ... For structure/union tags and members, ... declarator or type specifier). ...
    (comp.lang.c)
  • Re: Accessing local variable
    ... char * fun ... "4 Every other identifier has scope determined by the placement of its ... declaration (in a declarator or type specifier). ...
    (comp.lang.c)
  • Re: Portability regarding sizeof() function
    ... Appropriate use of sizeof is essential to writing portable code. ... That seems to define the end of the scope. ... Every other identifier has scope determined by the ... placement of its declaration (in a declarator or type ...
    (comp.lang.c)
  • Re: declaration shadows a parameter
    ... be a mistake to do so, but the only who knows that it is a mistake is the one who wrote the code. ... declared before the opening '{' of the scope. ... A label name is the only kind of identifier that has function scope. ... declaration (in a declarator or type specifier). ...
    (comp.lang.c)
  • Re: scratch memory
    ... have function scope. ... "If the declarator or type specifier that declares ... the identifier appears inside a block or within the list ... of parameter declarations in a function definition, ...
    (comp.lang.c)