Strange behavior of pidof function

Discussion in 'Installation/Configuration' started by Poliman, Jun 25, 2018.

  1. Poliman

    Poliman Member

    I have application based on node server file. The path to it:
    Code:
    /var/www/clients/client11/web28/web/nodejs/biodermagame
    
    directory listing:
    Code:
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# ls
    biogame-server.js  biogame-server-local.js  biogame-server-prod.js  config  libs  modules  node_modules  package.json  package-lock.json  webpack.node.js
    
    Server file is biogame-server-prod.js and it is running but somehow pidof function does not find the process id under:
    Code:
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame-server-prod.js
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame-server-prod.j
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame-server-prod.
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame-server-pro
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame-server-pr
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame-server-p
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame-server-
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame-server
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame-serve
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame-serv
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame-ser
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame-se
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame-s
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame-
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogame
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biogam
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof bioga
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof biog
    
    but under "bio":
    Code:
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# pidof bio
    28405
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame#
    
    Server process is biogame-server-prod.js as shows attached screen from ProcessMonitor2 (pm2 for node servers). Does anybody know what happens?

    PS
    I wrote another example here.
     

    Attached Files:

  2. ahrasis

    ahrasis Active Member

    I don't think there is any formal support for node.js here, but I could be wrong.
     
  3. Poliman

    Poliman Member

    I wrote thread here, because I think it's not related with node but with pidof function, which is Linux thing and here are many Linux specialists. :) I thought that maybe for some node servers is too long path and pidof cut some letters, because for one node server is path:
    Code:
    /var/www/clients/client11/web28/web/nodejs/biodermagame/biogame-server-prod.js
    and result of pidof is like I put in earlier post, but for example this server
    Code:
    /var/www/clients/client31/web91/web/quiz3m-server-prod.js
    has result without cutting any letters:
    Code:
    [email protected]:~#pidof quiz3m-server-prod.js
    22836
    Another example with testing env node server:
    Code:
    /var/www/clients/client4/web4/web/tquiz3m/quiz3m-server-test.js
    has result with cutting letters:
    Code:
    [email protected]:~#pidof quiz3m-server-tes
    1763
    
     
    Last edited: Jun 26, 2018
  4. Taleman

    Taleman Active Member HowtoForge Supporter

    You should check what is the name of the process with:
    Code:
    ps -ef | grep -i bio
     
  5. Poliman

    Poliman Member

    There is output:
    Code:
    [email protected]:~# ps -ef | grep -i bio
    root      8368  2084  0 10:37 ?        00:00:01 node /var/www/clients/client11/web28/web/nodejs/biodermagame/bio
    but there isn't server file called "bio":
    Code:
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame# ls -l
    total 412
    -rw-r--r--   1 web28 client11    816 Jun 21 13:54 biogame-server.js
    -rw-r--r--   1 web28 client11  16063 Jun 21 13:54 biogame-server-local.js
    -rw-r--r--   1 web28 client11  16384 Jun 25 11:22 biogame-server-prod.js
    drwxr-xr-x   3 web28 client11   4096 Jun 21 13:54 config
    drwxr-xr-x   2 web28 client11   4096 Jun 21 13:54 libs
    drwxr-xr-x   3 web28 client11   4096 Jun 21 13:54 modules
    drwxr-xr-x 773 root  root      28672 Jun 25 10:12 node_modules
    -rw-r--r--   1 web28 client11   1065 Jun 21 13:54 package.json
    -rw-r--r--   1 web28 client11 332632 Jun 25 10:12 package-lock.json
    -rw-r--r--   1 web28 client11   2272 Jun 21 13:54 webpack.node.js
    
     
  6. Stephan Ververda

    Stephan Ververda Member HowtoForge Supporter

    Actually the process is node and not bio. The /var/www/clients/client11/web28/web/nodejs/biodermagam/bio is just the parameter of node. So it seems that node.js is cutting it off and not pidof.

    From what i have been reading this might have to do with how parameters are given to node.js.

    You might try to execute it manually in the following ways:
    1. run node.js with the entire path to the server as parameter
    2. go to the folder were the server is located and run node.js with only the servername (excluding the path)
    and see what the results into after doing another
    ps -ef | grep -i bio
     
    Last edited: Jun 26, 2018
    Poliman likes this.
  7. Poliman

    Poliman Member

    When run:
    Code:
    node /var/www/clients/client11/web28/web/nodejs/biodermagame/biogame-server-prod.js
    I have - result of ps -ef | grep -i bio ("bio" in biodermagame and in biogame-server-prod.js are marked in red):
    Code:
    root     18428  3761  2 15:08 pts/0    00:00:01 node /var/www/clients/client11/web28/web/nodejs/biodermagame/biogame-server-prod.js
    pidof result:
    Code:
    [email protected]:~# pidof biogame-server-prod.js
    [email protected]:~# pidof /var/www/clients/client11/web28/web/nodejs/biodermagame/biogame-server-prod.js
    [email protected]:~# pidof bio
    [email protected]:~#
    
    ---
    When run from path /var/www/clients/client11/web28/web/nodejs/biodermagame where is stored server file:
    Code:
    [email protected]:~# cd /var/www/clients/client11/web28/web/nodejs/biodermagame/
    [email protected]:/var/www/clients/client11/web28/web/nodejs/biodermagame#node biogame-server-prod.js
    
    pidof result:
    Code:
    [email protected]:~# pidof bio
    [email protected]:~# pidof biogame-server-prod.js
    [email protected]:~# pidof /var/www/clients/client11/web28/web/nodejs/biodermagame/biogame-server-prod.js
    [email protected]:~#
    
    result of ps -ef | grep -i bio:
    Code:
    [email protected]:~# ps -ef | grep -i bio
    root     25403  3761  0 15:15 pts/0    00:00:01 node biogame-server-prod.js
    PS
    When I run this server using ProcessManager2, there is something funny:
    Code:
    [email protected]:~# pm2 start /var/www/clients/client11/web28/web/nodejs/biodermagame/biogame-server-prod.js
    [email protected]:~# ps -ef | grep -i bio
    root     26669  2084  0 15:20 ?        00:00:01 node /var/www/clients/client11/web28/web/nodejs/biodermagame/bio
    [email protected]:~# ps -ef | grep 26669
    root     26669  2084  0 15:20 ?        00:00:01 node /var/www/clients/client11/web28/web/nodejs/biodermagame/bio
    [email protected]:~# pidof bio
    26669
    
    So it looks like ProcessManager cut letters but why...
     
    Last edited: Jun 26, 2018
  8. Stephan Ververda

    Stephan Ververda Member HowtoForge Supporter

    Hmm... so in both cases it's actually showing the parameter completely, including the long path. So it's definitely not a node.js problem, neither a pidof problem.
    However when you run the application manually pidof is not finding anything...., it should be showing though if you run
    Code:
    pidof -x %scriptname%
    But the point of this test was to see if the scriptname would get cutoff or not, and it's not.
    What proces/application/script is responsible for starting the server? have a look at that, how it passes the parameter to node.js.
     
    Last edited: Jun 26, 2018
  9. Poliman

    Poliman Member

    I uses ProcessManager2 (pm2), because then started node server works also when console is closed. So it looks like ProcessManager cut letters. Hmm...
     
  10. Stephan Ververda

    Stephan Ververda Member HowtoForge Supporter

    So basically with
    Code:
    pm2 start %scriptname%
    How about trying with with the scriptname inside quotes?
     
  11. Poliman

    Poliman Member

    Script name in form like below?
    Code:
    pm2 start %/var/www/clients/client11/web28/web/nodejs/biodermagame/biogame-server-prod.js%
     
  12. Stephan Ververda

    Stephan Ververda Member HowtoForge Supporter

    no, in this form
    Code:
    pm2 start '/var/www/clients/client11/web28/web/nodejs/biodermagame/biogame-server-prod.js'
    I must immediately say i don't know pm2 that well (or at all :)) but i read here and there a problem of passing these parameters without quotes inside javascripts to nodejs
     
  13. Poliman

    Poliman Member

    Thank you I will check it. ;)

    EDIT
    I checked. Result is exactly this same like without quotes.
     
    Last edited: Jun 28, 2018
  14. Stephan Ververda

    Stephan Ververda Member HowtoForge Supporter

  15. Poliman

    Poliman Member

    Yea, very good idea. I suppose I will have to describe whole problem in details there. :p

    PS
    I have created some thread
     
    Last edited: Jun 29, 2018

Share This Page