0

In Linux, what happens to the state of a process (curl, postman, mule, caml) when it has sent a HTTP request and waiting for a HTTP response? What is the way to know how long the process is waiting for the response?

mon
  • 225
  • 3
  • 9
  • 1
    Depends on what exactly generated that request. For example, if you are developing in Angular or hosting an Angular app on Linux, any http request is asynchronous and can take several seconds for the data to show up. Angular deals with this by making `promises` and then filling them when the data is returned. Royal PITA to deal with. In Java, some http request libraries are synchronous, some are asynchronous. PHP, cURL, etc. are all synchronous. So... It Depends? – ivanivan Mar 27 '18 at 11:55
  • @ivanivan, thanks for the suggestion. Update the question. – mon Mar 27 '18 at 21:26

1 Answers1

2

After the update to the question, my comment of -

Depends on what exactly generated that request. For example, if you are developing in Angular or hosting an Angular app on Linux, any http request is asynchronous and can take several seconds for the data to show up. Angular deals with this by making promises and then filling them when the data is returned. Royal PITA to deal with. In Java, some http request libraries are synchronous, some are asynchronous. PHP, cURL, etc. are all synchronous. So... It Depends?

Still applies. Have headers been sent, but waiting on data transmission to start? Waiting on headers? Half the data has been sent but there is a temporary transmission pause?

Anyway, curl reports as "sleeping", didn't want to deal with writing more code and experimenting for the others. Perhaps some method of relating voluntary context switches to elapsed time would work?

With curl, and a simple script -

<?php
sleep(60);
print("done");
?>

a curl http://localhost/wait.php shows in /proc/PID/status that it is sleeping. No indicator of time that I can see - here's the output, note I had to start the curl, click to change focus, etc. so more than a few seconds into it

user@darkstar /proc/4816 $ cat status
Name:   curl
Umask:  0022
State:  S (sleeping)
Tgid:   4816
Ngid:   0
Pid:    4816
PPid:   4729
TracerPid:  0
Uid:    1000    1000    1000    1000
Gid:    1000    1000    1000    1000
FDSize: 256
Groups: 4 24 27 30 44 46 113 130 132 135 1000 
NStgid: 4816
NSpid:  4816
NSpgid: 4816
NSsid:  4729
VmPeak:   225592 kB
VmSize:   162176 kB
VmLck:         0 kB
VmPin:         0 kB
VmHWM:      5692 kB
VmRSS:      5616 kB
RssAnon:         800 kB
RssFile:        4816 kB
RssShmem:          0 kB
VmData:     9172 kB
VmStk:       136 kB
VmExe:       176 kB
VmLib:     10392 kB
VmPTE:       184 kB
VmPMD:        12 kB
VmSwap:        0 kB
HugetlbPages:          0 kB
Threads:    1
SigQ:   0/31484
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000001000
SigCgt: 0000000180000000
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 0000003fffffffff
CapAmb: 0000000000000000
Seccomp:    0
Cpus_allowed:   ffff
Cpus_allowed_list:  0-15
Mems_allowed:   00000000,00000001
Mems_allowed_list:  0
voluntary_ctxt_switches:    33
nonvoluntary_ctxt_switches: 2

And a (better) time command run -

user@darkstar:~ $ /usr/bin/time -v curl http://localhost/wait.php
Done    Command being timed: "curl http://localhost/wait.php"
    User time (seconds): 0.00
    System time (seconds): 0.00
    Percent of CPU this job got: 0%
    Elapsed (wall clock) time (h:mm:ss or m:ss): 1:00.01
    Average shared text size (kbytes): 0
    Average unshared data size (kbytes): 0
    Average stack size (kbytes): 0
    Average total size (kbytes): 0
    Maximum resident set size (kbytes): 7596
    Average resident set size (kbytes): 0
    Major (requiring I/O) page faults: 0
    Minor (reclaiming a frame) page faults: 403
    Voluntary context switches: 63
    Involuntary context switches: 2
    Swaps: 0
    File system inputs: 0
    File system outputs: 0
    Socket messages sent: 0
    Socket messages received: 0
    Signals delivered: 0
    Page size (bytes): 4096
    Exit status: 0
ivanivan
  • 1,448
  • 6
  • 6