Mental-model of multiprocessing?

Discussion in 'Linux Networking' started by Avoid9Pdf, Mar 27, 2013.

  1. Avoid9Pdf

    Avoid9Pdf Guest

    For someone who knows the stacked-subroutine-calling mechanism
    [down to the silicon level], and resists the little-men-in-the-box
    mental model, it's difficult to UNDERSTAND how to build a script that:
    calls a URL via openssl,
    conducts a dialog with the remote server,
    and saves the log of the process in a file.
    --
    My main difficulty seems to be that apparently the 'routines'
    are NOT stacked:
    User's shell > Script > openssl > REPEAT{dialog; log}.
    The dialog-steps must be <WRAPPED> in the openssl.

    How does openssl know when to <return>?

    Here's a snipppet of related script which I don't understand:---
    # Author Pascal B..
    local_name=localhost
    if [ "$1" = "--log" ] ; then shift ; trace=echo ; else trace=true ; fi
    log=/dev/tty
    message=/tmp/message.$$
    cat>$message
    (
    read line 0<&3 ; $trace "$line">$log
    case "$line" in 2*) ;; *) echo "QUIT" 1>&3 ; exit 0 ;; esac
    echo "HELO $local_name" 1>&3
    read line 0<&3 ; $trace "$line">$log
    case "$line" in 2*) ;; *) echo "QUIT" 1>&3 ; exit 0 ;; esac
    echo "MAIL FROM: <${from}>" 1>&3
    ....
    echo "QUIT" 1>&3
    ) 3<>/dev/tcp/$smtp_server/25
    ==== end of script snippet

    What's the meaning of:
    cat>/tmp/mesgFile
    (
    read line 0<&3 ; echo "$line">$log
    case "$line" in 2*) ;; *) echo "QUIT" 1>&3 ; exit 0 ;; esac
    echo "HELO $local_name" 1>&3
    ) 3<>/dev/tcp/$smtp_server/25
    ??!

    Where's to doco/man for the syntax:-
    cat>/File
    ( <read; select; write> ) 3<>/dev/tcp/URL/PORT
    ??!

    How is data read from /dev/tty ?

    # echo dog > /dev/tty
    # cat /dev/tty
    # echo dog > /dev/tty ; cat /dev/tty
    give unexpected results FOR ME

    /dev/tty seems to behave like $1 AND like $2 ?!?

    Apparently my confusion is about 'redirection' ?

    So, where's a good mental-model of multiprocessing,
    documented?

    Thanks for any pointers/explanations.
     
    Avoid9Pdf, Mar 27, 2013
    #1
    1. Advertisements

  2. NB that on modern systems there’s a good chance that the concurrency is
    real, not (just) simulated through time-slicing. In shell programming
    this makes little practical difference; in (for instance) C the
    implications rather are more interesting.
     
    Richard Kettlewell, Mar 27, 2013
    #2
    1. Advertisements

  3. you mean there are multiple cores running different processes in
    different RAM spaces?

    Fancy giving an overview of that? to add to the interest?



    In shell programming
    I haven't looked at C stuff at that level - are their calls to spin
    threads into different cores available?

    I had assumed that the kernel itself would allocate CPUs to active
    tasks, on the basis of whichever CPU had less going on, but not that a
    given user level program would be able to control that ..




    --
    Ineptocracy

    (in-ep-toc’-ra-cy) – a system of government where the least capable to
    lead are elected by the least capable of producing, and where the
    members of society least likely to sustain themselves or succeed, are
    rewarded with goods and services paid for by the confiscated wealth of a
    diminishing number of producers.
     
    The Natural Philosopher, Mar 27, 2013
    #3
  4. Avoid9Pdf

    Chris Davies Guest

    $ man -k affinity
    pthread_attr_getaffinity_np (3) - set/get CPU affinity attribute in thread attributes object
    pthread_attr_setaffinity_np (3) - set/get CPU affinity attribute in thread attributes object
    pthread_getaffinity_np (3) - set/get CPU affinity of a thread
    pthread_setaffinity_np (3) - set/get CPU affinity of a thread
    sched_getaffinity (2) - set and get a process's CPU affinity mask
    sched_setaffinity (2) - set and get a process's CPU affinity mask
    taskset (1) - retrieve or set a process's CPU affinity

    Chris
     
    Chris Davies, Mar 27, 2013
    #4
  5. now that will be stored in these vintage memory banks in case its handy
    one day.

    Thank you.


    --
    Ineptocracy

    (in-ep-toc’-ra-cy) – a system of government where the least capable to
    lead are elected by the least capable of producing, and where the
    members of society least likely to sustain themselves or succeed, are
    rewarded with goods and services paid for by the confiscated wealth of a
    diminishing number of producers.
     
    The Natural Philosopher, Mar 27, 2013
    #5
  6. Yes. Strictly, different virtual memory address spaces. Also, multiple
    threads of a single process running on different cores but sharing
    virtual memory.
    I’m not sure there’s much to say: it’s the same as SMP always was, but
    now you get multiple cores[1] on a single die and it happens on
    computers all the way down to smartphones and netbooks, not just hugely
    expensive machines.

    [1] Or parts of cores; exactly what is shared and what is duplicated
    varies.
    It’s possible to bind a particular thread (or process) to a particular
    core. Whether it’s actually worthwhile depends on the task at hand.

    But what I was alluding to is that caches aren’t completely transparent.
    The immediate practical implication of this is that sequential
    consistency is no longer preserved. A multi-threaded program written
    assuming that it is, or even without that assumption as such but only
    previously tested on a single-core system, is likely to misbehave on a
    multi-core system.

    http://en.wikipedia.org/wiki/Memory_ordering discusses.
     
    Richard Kettlewell, Mar 27, 2013
    #6
  7. thanks for that. Not issues I have to deal with, but you never know.


    --
    Ineptocracy

    (in-ep-toc’-ra-cy) – a system of government where the least capable to
    lead are elected by the least capable of producing, and where the
    members of society least likely to sustain themselves or succeed, are
    rewarded with goods and services paid for by the confiscated wealth of a
    diminishing number of producers.
     
    The Natural Philosopher, Mar 27, 2013
    #7
  8. Avoid9Pdf

    Jorgen Grahn Guest

    ["Followup-To:" header set to comp.os.linux.misc.]

    .
    The difference is sometimes practical in shell programming, too; a
    pipeline may run significantly faster, if it's CPU-bound in more than
    one place. This has mattered to me in some real scenarios.

    /Jorgen
     
    Jorgen Grahn, Mar 27, 2013
    #8
  9. Avoid9Pdf

    Aragorn Guest

    And it gets even more complicated with NUMA. The AMD-proper
    implementations of AMD64 were conceived from the ground up as (cc)NUMA -
    for Intel, it took them up until the i7 architecture before they started
    integrating the memory controller on the processor die.
     
    Aragorn, Mar 28, 2013
    #9
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.